zefyr

gallery_item.dart 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo_manager/photo_manager.dart';
  4. import 'iconfont.dart';
  5. import 'theme.dart';
  6. class GalleryItem extends StatefulWidget {
  7. const GalleryItem({Key key, this.asset}) : super(key: key);
  8. final AssetEntity asset;
  9. @override
  10. _GalleryItemState createState() => _GalleryItemState();
  11. }
  12. class _GalleryItemState extends State<GalleryItem> {
  13. final ValueNotifier<bool> _checked = ValueNotifier<bool>(false);
  14. Uint8List _thumbData;
  15. @override
  16. Widget build(BuildContext context) {
  17. final theme = ZefyrTheme.of(context).toolbarTheme;
  18. return Stack(
  19. children: <Widget>[
  20. GestureDetector(
  21. behavior: HitTestBehavior.opaque,
  22. child: Container(
  23. height: 210,
  24. margin: EdgeInsets.only(left: 4),
  25. child: _thumbData != null
  26. ? Image.memory(
  27. _thumbData,
  28. fit: BoxFit.cover,
  29. )
  30. : FutureBuilder<Uint8List>(
  31. future: widget.asset.thumbData,
  32. builder: (BuildContext context, snapshot) {
  33. Widget w;
  34. if (snapshot.hasError) {
  35. w = ErrorWidget(snapshot.error);
  36. } else if (snapshot.hasData) {
  37. _thumbData = snapshot.data;
  38. w = Image.memory(
  39. snapshot.data,
  40. fit: BoxFit.cover,
  41. );
  42. } else {
  43. w = Center(
  44. child: Container(
  45. color: Colors.white,
  46. padding: const EdgeInsets.all(20),
  47. child: CircularProgressIndicator(),
  48. ),
  49. );
  50. }
  51. return w;
  52. },
  53. ),
  54. ),
  55. onTap: () {},
  56. ),
  57. Positioned(
  58. top: 6,
  59. right: 6,
  60. child: ValueListenableBuilder(
  61. valueListenable: _checked,
  62. builder: (BuildContext context, bool value, Widget child) {
  63. return GestureDetector(
  64. behavior: HitTestBehavior.opaque,
  65. onTap: () {
  66. _checked.value = !value;
  67. },
  68. child: Icon(
  69. IconFont.list_update_complete,
  70. size: 24,
  71. color: value ? theme.toggleColor : Colors.white,
  72. ),
  73. );
  74. },
  75. ),
  76. ),
  77. ],
  78. );
  79. }
  80. }