Bladeren bron

update duration badge and example

cjl_macbook 6 jaren geleden
bovenliggende
commit
8cf7ab73b6
7 gewijzigde bestanden met toevoegingen van 83 en 262 verwijderingen
  1. 13
    0
      .vscode/launch.json
  2. 2
    0
      example/lib/main.dart
  3. 1
    0
      lib/photo.dart
  4. 42
    6
      lib/src/delegate/badge_delegate.dart
  5. 18
    4
      lib/src/ui/page/photo_main_page.dart
  6. 6
    251
      pubspec.lock
  7. 1
    1
      pubspec.yaml

+ 13
- 0
.vscode/launch.json Bestand weergeven

@@ -0,0 +1,13 @@
1
+{
2
+    // 使用 IntelliSense 了解相关属性。 
3
+    // 悬停以查看现有属性的描述。
4
+    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5
+    "version": "0.2.0",
6
+    "configurations": [
7
+        {
8
+            "name": "Flutter",
9
+            "request": "launch",
10
+            "type": "dart"
11
+        }
12
+    ]
13
+}

+ 2
- 0
example/lib/main.dart Bestand weergeven

@@ -66,6 +66,8 @@ class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
66 66
 
67 67
       loadingDelegate: this,
68 68
       // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
69
+
70
+      badgeDelegate: const DurationBadgeDelegate(),
69 71
     );
70 72
 
71 73
     if (imgList == null) {

+ 1
- 0
lib/photo.dart Bestand weergeven

@@ -18,6 +18,7 @@ export 'package:photo/src/delegate/loading_delegate.dart';
18 18
 export 'package:photo/src/delegate/sort_delegate.dart';
19 19
 export 'package:photo/src/provider/i18n_provider.dart'
20 20
     show I18NCustomProvider, I18nProvider, CNProvider, ENProvider;
21
+export 'package:photo/src/delegate/badge_delegate.dart';
21 22
 
22 23
 class PhotoPicker {
23 24
   static PhotoPicker _instance;

+ 42
- 6
lib/src/delegate/badge_delegate.dart Bestand weergeven

@@ -4,7 +4,7 @@ import 'package:photo_manager/photo_manager.dart';
4 4
 abstract class BadgeDelegate {
5 5
   const BadgeDelegate();
6 6
 
7
-  Widget buildBadge(BuildContext context, AssetType type);
7
+  Widget buildBadge(BuildContext context, AssetType type, Duration duration);
8 8
 }
9 9
 
10 10
 class DefaultBadgeDelegate extends BadgeDelegate {
@@ -15,13 +15,10 @@ class DefaultBadgeDelegate extends BadgeDelegate {
15 15
   });
16 16
 
17 17
   @override
18
-  Widget buildBadge(BuildContext context, AssetType type) {
18
+  Widget buildBadge(BuildContext context, AssetType type, Duration duration) {
19 19
     if (type == AssetType.video) {
20 20
       return Padding(
21
-        padding: const EdgeInsets.only(
22
-          top: 2.0,
23
-          left: 2.0,
24
-        ),
21
+        padding: const EdgeInsets.all(2.0),
25 22
         child: Align(
26 23
           alignment: alignment,
27 24
           child: Container(
@@ -45,3 +42,42 @@ class DefaultBadgeDelegate extends BadgeDelegate {
45 42
     return Container();
46 43
   }
47 44
 }
45
+
46
+class DurationBadgeDelegate extends BadgeDelegate {
47
+  final AlignmentGeometry alignment;
48
+  const DurationBadgeDelegate({this.alignment = Alignment.bottomRight});
49
+
50
+  @override
51
+  Widget buildBadge(BuildContext context, AssetType type, Duration duration) {
52
+    if (type == AssetType.video) {
53
+      var s = duration.inSeconds;
54
+      var m = duration.inMinutes;
55
+      var h = duration.inHours;
56
+
57
+      String text =
58
+          "$h:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}";
59
+
60
+      return Padding(
61
+        padding: const EdgeInsets.all(2.0),
62
+        child: Align(
63
+          alignment: alignment,
64
+          child: Container(
65
+            decoration: BoxDecoration(
66
+              color: Theme.of(context).primaryColor.withOpacity(0.65),
67
+            ),
68
+            child: Text(
69
+              text,
70
+              style: const TextStyle(
71
+                fontSize: 12.0,
72
+                color: Colors.white,
73
+              ),
74
+            ),
75
+            padding: const EdgeInsets.all(4.0),
76
+          ),
77
+        ),
78
+      );
79
+    }
80
+
81
+    return Container();
82
+  }
83
+}

+ 18
- 4
lib/src/ui/page/photo_main_page.dart Bestand weergeven

@@ -540,10 +540,24 @@ class ImageItem extends StatelessWidget {
540 540
       height: double.infinity,
541 541
       fit: BoxFit.cover,
542 542
     );
543
-    var badge = badgeDelegate?.buildBadge(context, entity.type);
544
-    if (badge == null) {
545
-      return image;
546
-    }
543
+    // FutureBuilder()
544
+    var badge = FutureBuilder<Duration>(
545
+      future: entity.videoDuration,
546
+      builder: (ctx, snapshot) {
547
+        if (snapshot.hasData && snapshot != null) {
548
+          var buildBadge =
549
+              badgeDelegate?.buildBadge(context, entity.type, snapshot.data);
550
+          if (buildBadge == null) {
551
+            return Container();
552
+          } else {
553
+            return buildBadge;
554
+          }
555
+        }else{
556
+          return Container();
557
+        }
558
+      },
559
+    );
560
+
547 561
     return Stack(
548 562
       children: <Widget>[
549 563
         image,

+ 6
- 251
pubspec.lock Bestand weergeven

@@ -1,20 +1,6 @@
1 1
 # Generated by pub
2 2
 # See https://www.dartlang.org/tools/pub/glossary#lockfile
3 3
 packages:
4
-  analyzer:
5
-    dependency: transitive
6
-    description:
7
-      name: analyzer
8
-      url: "https://pub.flutter-io.cn"
9
-    source: hosted
10
-    version: "0.32.4"
11
-  args:
12
-    dependency: transitive
13
-    description:
14
-      name: args
15
-      url: "https://pub.flutter-io.cn"
16
-    source: hosted
17
-    version: "1.5.0"
18 4
   async:
19 5
     dependency: transitive
20 6
     description:
@@ -43,27 +29,6 @@ packages:
43 29
       url: "https://pub.flutter-io.cn"
44 30
     source: hosted
45 31
     version: "1.14.11"
46
-  convert:
47
-    dependency: transitive
48
-    description:
49
-      name: convert
50
-      url: "https://pub.flutter-io.cn"
51
-    source: hosted
52
-    version: "2.0.2"
53
-  crypto:
54
-    dependency: transitive
55
-    description:
56
-      name: crypto
57
-      url: "https://pub.flutter-io.cn"
58
-    source: hosted
59
-    version: "2.0.6"
60
-  csslib:
61
-    dependency: transitive
62
-    description:
63
-      name: csslib
64
-      url: "https://pub.flutter-io.cn"
65
-    source: hosted
66
-    version: "0.14.5"
67 32
   flutter:
68 33
     dependency: "direct main"
69 34
     description: flutter
@@ -74,83 +39,6 @@ packages:
74 39
     description: flutter
75 40
     source: sdk
76 41
     version: "0.0.0"
77
-  front_end:
78
-    dependency: transitive
79
-    description:
80
-      name: front_end
81
-      url: "https://pub.flutter-io.cn"
82
-    source: hosted
83
-    version: "0.1.4"
84
-  glob:
85
-    dependency: transitive
86
-    description:
87
-      name: glob
88
-      url: "https://pub.flutter-io.cn"
89
-    source: hosted
90
-    version: "1.1.7"
91
-  html:
92
-    dependency: transitive
93
-    description:
94
-      name: html
95
-      url: "https://pub.flutter-io.cn"
96
-    source: hosted
97
-    version: "0.13.3+3"
98
-  http:
99
-    dependency: transitive
100
-    description:
101
-      name: http
102
-      url: "https://pub.flutter-io.cn"
103
-    source: hosted
104
-    version: "0.11.3+17"
105
-  http_multi_server:
106
-    dependency: transitive
107
-    description:
108
-      name: http_multi_server
109
-      url: "https://pub.flutter-io.cn"
110
-    source: hosted
111
-    version: "2.0.5"
112
-  http_parser:
113
-    dependency: transitive
114
-    description:
115
-      name: http_parser
116
-      url: "https://pub.flutter-io.cn"
117
-    source: hosted
118
-    version: "3.1.3"
119
-  io:
120
-    dependency: transitive
121
-    description:
122
-      name: io
123
-      url: "https://pub.flutter-io.cn"
124
-    source: hosted
125
-    version: "0.3.3"
126
-  js:
127
-    dependency: transitive
128
-    description:
129
-      name: js
130
-      url: "https://pub.flutter-io.cn"
131
-    source: hosted
132
-    version: "0.6.1+1"
133
-  json_rpc_2:
134
-    dependency: transitive
135
-    description:
136
-      name: json_rpc_2
137
-      url: "https://pub.flutter-io.cn"
138
-    source: hosted
139
-    version: "2.0.9"
140
-  kernel:
141
-    dependency: transitive
142
-    description:
143
-      name: kernel
144
-      url: "https://pub.flutter-io.cn"
145
-    source: hosted
146
-    version: "0.3.4"
147
-  logging:
148
-    dependency: transitive
149
-    description:
150
-      name: logging
151
-      url: "https://pub.flutter-io.cn"
152
-    source: hosted
153
-    version: "0.11.3+2"
154 42
   matcher:
155 43
     dependency: transitive
156 44
     description:
@@ -165,41 +53,6 @@ packages:
165 53
       url: "https://pub.flutter-io.cn"
166 54
     source: hosted
167 55
     version: "1.1.6"
168
-  mime:
169
-    dependency: transitive
170
-    description:
171
-      name: mime
172
-      url: "https://pub.flutter-io.cn"
173
-    source: hosted
174
-    version: "0.9.6+2"
175
-  multi_server_socket:
176
-    dependency: transitive
177
-    description:
178
-      name: multi_server_socket
179
-      url: "https://pub.flutter-io.cn"
180
-    source: hosted
181
-    version: "1.0.2"
182
-  node_preamble:
183
-    dependency: transitive
184
-    description:
185
-      name: node_preamble
186
-      url: "https://pub.flutter-io.cn"
187
-    source: hosted
188
-    version: "1.4.4"
189
-  package_config:
190
-    dependency: transitive
191
-    description:
192
-      name: package_config
193
-      url: "https://pub.flutter-io.cn"
194
-    source: hosted
195
-    version: "1.0.5"
196
-  package_resolver:
197
-    dependency: transitive
198
-    description:
199
-      name: package_resolver
200
-      url: "https://pub.flutter-io.cn"
201
-    source: hosted
202
-    version: "1.0.4"
203 56
   path:
204 57
     dependency: transitive
205 58
     description:
@@ -213,82 +66,19 @@ packages:
213 66
       name: photo_manager
214 67
       url: "https://pub.flutter-io.cn"
215 68
     source: hosted
216
-    version: "0.1.8"
217
-  plugin:
218
-    dependency: transitive
219
-    description:
220
-      name: plugin
221
-      url: "https://pub.flutter-io.cn"
222
-    source: hosted
223
-    version: "0.2.0+3"
224
-  pool:
225
-    dependency: transitive
226
-    description:
227
-      name: pool
228
-      url: "https://pub.flutter-io.cn"
229
-    source: hosted
230
-    version: "1.3.6"
231
-  pub_semver:
232
-    dependency: transitive
233
-    description:
234
-      name: pub_semver
235
-      url: "https://pub.flutter-io.cn"
236
-    source: hosted
237
-    version: "1.4.2"
69
+    version: "0.1.9"
238 70
   quiver:
239 71
     dependency: transitive
240 72
     description:
241 73
       name: quiver
242 74
       url: "https://pub.flutter-io.cn"
243 75
     source: hosted
244
-    version: "2.0.0+1"
245
-  shelf:
246
-    dependency: transitive
247
-    description:
248
-      name: shelf
249
-      url: "https://pub.flutter-io.cn"
250
-    source: hosted
251
-    version: "0.7.3+3"
252
-  shelf_packages_handler:
253
-    dependency: transitive
254
-    description:
255
-      name: shelf_packages_handler
256
-      url: "https://pub.flutter-io.cn"
257
-    source: hosted
258
-    version: "1.0.4"
259
-  shelf_static:
260
-    dependency: transitive
261
-    description:
262
-      name: shelf_static
263
-      url: "https://pub.flutter-io.cn"
264
-    source: hosted
265
-    version: "0.2.8"
266
-  shelf_web_socket:
267
-    dependency: transitive
268
-    description:
269
-      name: shelf_web_socket
270
-      url: "https://pub.flutter-io.cn"
271
-    source: hosted
272
-    version: "0.2.2+4"
76
+    version: "2.0.1"
273 77
   sky_engine:
274 78
     dependency: transitive
275 79
     description: flutter
276 80
     source: sdk
277 81
     version: "0.0.99"
278
-  source_map_stack_trace:
279
-    dependency: transitive
280
-    description:
281
-      name: source_map_stack_trace
282
-      url: "https://pub.flutter-io.cn"
283
-    source: hosted
284
-    version: "1.1.5"
285
-  source_maps:
286
-    dependency: transitive
287
-    description:
288
-      name: source_maps
289
-      url: "https://pub.flutter-io.cn"
290
-    source: hosted
291
-    version: "0.10.7"
292 82
   source_span:
293 83
     dependency: transitive
294 84
     description:
@@ -324,13 +114,13 @@ packages:
324 114
       url: "https://pub.flutter-io.cn"
325 115
     source: hosted
326 116
     version: "1.0.1"
327
-  test:
117
+  test_api:
328 118
     dependency: transitive
329 119
     description:
330
-      name: test
120
+      name: test_api
331 121
       url: "https://pub.flutter-io.cn"
332 122
     source: hosted
333
-    version: "1.3.0"
123
+    version: "0.2.1"
334 124
   typed_data:
335 125
     dependency: transitive
336 126
     description:
@@ -338,13 +128,6 @@ packages:
338 128
       url: "https://pub.flutter-io.cn"
339 129
     source: hosted
340 130
     version: "1.1.6"
341
-  utf:
342
-    dependency: transitive
343
-    description:
344
-      name: utf
345
-      url: "https://pub.flutter-io.cn"
346
-    source: hosted
347
-    version: "0.9.0+5"
348 131
   vector_math:
349 132
     dependency: transitive
350 133
     description:
@@ -352,33 +135,5 @@ packages:
352 135
       url: "https://pub.flutter-io.cn"
353 136
     source: hosted
354 137
     version: "2.0.8"
355
-  vm_service_client:
356
-    dependency: transitive
357
-    description:
358
-      name: vm_service_client
359
-      url: "https://pub.flutter-io.cn"
360
-    source: hosted
361
-    version: "0.2.6"
362
-  watcher:
363
-    dependency: transitive
364
-    description:
365
-      name: watcher
366
-      url: "https://pub.flutter-io.cn"
367
-    source: hosted
368
-    version: "0.9.7+10"
369
-  web_socket_channel:
370
-    dependency: transitive
371
-    description:
372
-      name: web_socket_channel
373
-      url: "https://pub.flutter-io.cn"
374
-    source: hosted
375
-    version: "1.0.9"
376
-  yaml:
377
-    dependency: transitive
378
-    description:
379
-      name: yaml
380
-      url: "https://pub.flutter-io.cn"
381
-    source: hosted
382
-    version: "2.1.15"
383 138
 sdks:
384
-  dart: ">=2.0.0-dev.68.0 <3.0.0"
139
+  dart: ">=2.0.0 <3.0.0"

+ 1
- 1
pubspec.yaml Bestand weergeven

@@ -11,7 +11,7 @@ dependencies:
11 11
   flutter:
12 12
     sdk: flutter
13 13
 
14
-  photo_manager: ^0.1.8
14
+  photo_manager: ^0.1.9
15 15
   # photo_manager:
16 16
   #   git:
17 17
   #     url: https://github.com/CaiJingLong/flutter_photo_manager.git