Browse Source

update duration badge and example

cjl_macbook 6 years ago
parent
commit
8cf7ab73b6

+ 13
- 0
.vscode/launch.json View File

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 View File

66
 
66
 
67
       loadingDelegate: this,
67
       loadingDelegate: this,
68
       // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
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
     if (imgList == null) {
73
     if (imgList == null) {

+ 1
- 0
lib/photo.dart View File

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

+ 42
- 6
lib/src/delegate/badge_delegate.dart View File

4
 abstract class BadgeDelegate {
4
 abstract class BadgeDelegate {
5
   const BadgeDelegate();
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
 class DefaultBadgeDelegate extends BadgeDelegate {
10
 class DefaultBadgeDelegate extends BadgeDelegate {
15
   });
15
   });
16
 
16
 
17
   @override
17
   @override
18
-  Widget buildBadge(BuildContext context, AssetType type) {
18
+  Widget buildBadge(BuildContext context, AssetType type, Duration duration) {
19
     if (type == AssetType.video) {
19
     if (type == AssetType.video) {
20
       return Padding(
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
         child: Align(
22
         child: Align(
26
           alignment: alignment,
23
           alignment: alignment,
27
           child: Container(
24
           child: Container(
45
     return Container();
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 View File

540
       height: double.infinity,
540
       height: double.infinity,
541
       fit: BoxFit.cover,
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
     return Stack(
561
     return Stack(
548
       children: <Widget>[
562
       children: <Widget>[
549
         image,
563
         image,

+ 6
- 251
pubspec.lock View File

1
 # Generated by pub
1
 # Generated by pub
2
 # See https://www.dartlang.org/tools/pub/glossary#lockfile
2
 # See https://www.dartlang.org/tools/pub/glossary#lockfile
3
 packages:
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
   async:
4
   async:
19
     dependency: transitive
5
     dependency: transitive
20
     description:
6
     description:
43
       url: "https://pub.flutter-io.cn"
29
       url: "https://pub.flutter-io.cn"
44
     source: hosted
30
     source: hosted
45
     version: "1.14.11"
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
   flutter:
32
   flutter:
68
     dependency: "direct main"
33
     dependency: "direct main"
69
     description: flutter
34
     description: flutter
74
     description: flutter
39
     description: flutter
75
     source: sdk
40
     source: sdk
76
     version: "0.0.0"
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
   matcher:
42
   matcher:
155
     dependency: transitive
43
     dependency: transitive
156
     description:
44
     description:
165
       url: "https://pub.flutter-io.cn"
53
       url: "https://pub.flutter-io.cn"
166
     source: hosted
54
     source: hosted
167
     version: "1.1.6"
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
   path:
56
   path:
204
     dependency: transitive
57
     dependency: transitive
205
     description:
58
     description:
213
       name: photo_manager
66
       name: photo_manager
214
       url: "https://pub.flutter-io.cn"
67
       url: "https://pub.flutter-io.cn"
215
     source: hosted
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
   quiver:
70
   quiver:
239
     dependency: transitive
71
     dependency: transitive
240
     description:
72
     description:
241
       name: quiver
73
       name: quiver
242
       url: "https://pub.flutter-io.cn"
74
       url: "https://pub.flutter-io.cn"
243
     source: hosted
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
   sky_engine:
77
   sky_engine:
274
     dependency: transitive
78
     dependency: transitive
275
     description: flutter
79
     description: flutter
276
     source: sdk
80
     source: sdk
277
     version: "0.0.99"
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
   source_span:
82
   source_span:
293
     dependency: transitive
83
     dependency: transitive
294
     description:
84
     description:
324
       url: "https://pub.flutter-io.cn"
114
       url: "https://pub.flutter-io.cn"
325
     source: hosted
115
     source: hosted
326
     version: "1.0.1"
116
     version: "1.0.1"
327
-  test:
117
+  test_api:
328
     dependency: transitive
118
     dependency: transitive
329
     description:
119
     description:
330
-      name: test
120
+      name: test_api
331
       url: "https://pub.flutter-io.cn"
121
       url: "https://pub.flutter-io.cn"
332
     source: hosted
122
     source: hosted
333
-    version: "1.3.0"
123
+    version: "0.2.1"
334
   typed_data:
124
   typed_data:
335
     dependency: transitive
125
     dependency: transitive
336
     description:
126
     description:
338
       url: "https://pub.flutter-io.cn"
128
       url: "https://pub.flutter-io.cn"
339
     source: hosted
129
     source: hosted
340
     version: "1.1.6"
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
   vector_math:
131
   vector_math:
349
     dependency: transitive
132
     dependency: transitive
350
     description:
133
     description:
352
       url: "https://pub.flutter-io.cn"
135
       url: "https://pub.flutter-io.cn"
353
     source: hosted
136
     source: hosted
354
     version: "2.0.8"
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
 sdks:
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 View File

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