123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import 'dart:typed_data';
-
- import 'package:flutter/material.dart';
- import 'package:photo_manager/photo_manager.dart';
-
- import 'iconfont.dart';
- import 'theme.dart';
-
- class GalleryItem extends StatefulWidget {
- const GalleryItem({Key key, this.asset}) : super(key: key);
- final AssetEntity asset;
-
- @override
- _GalleryItemState createState() => _GalleryItemState();
- }
-
- class _GalleryItemState extends State<GalleryItem> {
- final ValueNotifier<bool> _checked = ValueNotifier<bool>(false);
- Uint8List _thumbData;
-
- @override
- Widget build(BuildContext context) {
- final theme = ZefyrTheme.of(context).toolbarTheme;
- return Stack(
- children: <Widget>[
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- child: Container(
- height: 210,
- margin: EdgeInsets.only(left: 4),
- child: _thumbData != null
- ? Image.memory(
- _thumbData,
- fit: BoxFit.cover,
- )
- : FutureBuilder<Uint8List>(
- future: widget.asset.thumbData,
- builder: (BuildContext context, snapshot) {
- Widget w;
- if (snapshot.hasError) {
- w = ErrorWidget(snapshot.error);
- } else if (snapshot.hasData) {
- _thumbData = snapshot.data;
- w = Image.memory(
- snapshot.data,
- fit: BoxFit.cover,
- );
- } else {
- w = Center(
- child: Container(
- color: Colors.white,
- padding: const EdgeInsets.all(20),
- child: CircularProgressIndicator(),
- ),
- );
- }
- return w;
- },
- ),
- ),
- onTap: () {},
- ),
- Positioned(
- top: 6,
- right: 6,
- child: ValueListenableBuilder(
- valueListenable: _checked,
- builder: (BuildContext context, bool value, Widget child) {
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- _checked.value = !value;
- },
- child: Icon(
- IconFont.list_update_complete,
- size: 24,
- color: value ? theme.toggleColor : Colors.white,
- ),
- );
- },
- ),
- ),
- ],
- );
- }
- }
|