|
@@ -0,0 +1,64 @@
|
|
1
|
+import 'dart:typed_data';
|
|
2
|
+
|
|
3
|
+import 'package:flutter/material.dart';
|
|
4
|
+import 'package:photo_manager/photo_manager.dart';
|
|
5
|
+
|
|
6
|
+class AssetImageWidget extends StatelessWidget {
|
|
7
|
+ final AssetEntity assetEntity;
|
|
8
|
+ final double width;
|
|
9
|
+ final double height;
|
|
10
|
+ final BoxFit boxFit;
|
|
11
|
+
|
|
12
|
+ const AssetImageWidget({
|
|
13
|
+ Key key,
|
|
14
|
+ @required this.assetEntity,
|
|
15
|
+ this.width,
|
|
16
|
+ this.height,
|
|
17
|
+ this.boxFit,
|
|
18
|
+ }) : super(key: key);
|
|
19
|
+
|
|
20
|
+ @override
|
|
21
|
+ Widget build(BuildContext context) {
|
|
22
|
+ if (assetEntity == null) {
|
|
23
|
+ return _buildContainer();
|
|
24
|
+ }
|
|
25
|
+ return FutureBuilder<Size>(
|
|
26
|
+ builder: (c, s) {
|
|
27
|
+ if (!s.hasData) {
|
|
28
|
+ return Container();
|
|
29
|
+ }
|
|
30
|
+ var size = s.data;
|
|
31
|
+ return FutureBuilder<Uint8List>(
|
|
32
|
+ builder: (BuildContext context, snapshot) {
|
|
33
|
+ if (snapshot.hasData) {
|
|
34
|
+ return _buildContainer(
|
|
35
|
+ child: Image.memory(
|
|
36
|
+ snapshot.data,
|
|
37
|
+ width: width,
|
|
38
|
+ height: height,
|
|
39
|
+ fit: boxFit,
|
|
40
|
+ ),
|
|
41
|
+ );
|
|
42
|
+ } else {
|
|
43
|
+ return _buildContainer();
|
|
44
|
+ }
|
|
45
|
+ },
|
|
46
|
+ future: assetEntity.thumbDataWithSize(
|
|
47
|
+ size.width.toInt(),
|
|
48
|
+ size.height.toInt(),
|
|
49
|
+ ),
|
|
50
|
+ );
|
|
51
|
+ },
|
|
52
|
+ future: assetEntity.size,
|
|
53
|
+ );
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ Widget _buildContainer({Widget child}) {
|
|
57
|
+ child ??= Container();
|
|
58
|
+ return Container(
|
|
59
|
+ width: width,
|
|
60
|
+ height: height,
|
|
61
|
+ child: child,
|
|
62
|
+ );
|
|
63
|
+ }
|
|
64
|
+}
|