|
@@ -14,6 +14,9 @@ import 'package:photo/src/ui/dialog/change_gallery_dialog.dart';
|
14
|
14
|
import 'package:photo/src/ui/page/photo_preview_page.dart';
|
15
|
15
|
import 'package:photo_manager/photo_manager.dart';
|
16
|
16
|
|
|
17
|
+part './main/bottom_widget.dart';
|
|
18
|
+part './main/image_item.dart';
|
|
19
|
+
|
17
|
20
|
class PhotoMainPage extends StatefulWidget {
|
18
|
21
|
final ValueChanged<List<AssetEntity>> onClose;
|
19
|
22
|
final Options options;
|
|
@@ -73,10 +76,14 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
73
|
76
|
_refreshList();
|
74
|
77
|
scaffoldKey = GlobalKey();
|
75
|
78
|
scrollController = ScrollController();
|
|
79
|
+ PhotoManager.addChangeCallback(_onAssetChange);
|
|
80
|
+ PhotoManager.startChangeNotify();
|
76
|
81
|
}
|
77
|
82
|
|
78
|
83
|
@override
|
79
|
84
|
void dispose() {
|
|
85
|
+ PhotoManager.removeChangeCallback(_onAssetChange);
|
|
86
|
+ PhotoManager.stopChangeNotify();
|
80
|
87
|
scaffoldKey = null;
|
81
|
88
|
super.dispose();
|
82
|
89
|
}
|
|
@@ -448,187 +455,6 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
448
|
455
|
),
|
449
|
456
|
);
|
450
|
457
|
}
|
451
|
|
-}
|
452
|
|
-
|
453
|
|
-class _BottomWidget extends StatefulWidget {
|
454
|
|
- final ValueChanged<AssetPathEntity> onGalleryChange;
|
455
|
|
-
|
456
|
|
- final Options options;
|
457
|
|
-
|
458
|
|
- final I18nProvider provider;
|
459
|
|
-
|
460
|
|
- final SelectedProvider selectedProvider;
|
461
|
|
-
|
462
|
|
- final String galleryName;
|
463
|
|
-
|
464
|
|
- final GalleryListProvider galleryListProvider;
|
465
|
|
- final VoidCallback onTapPreview;
|
466
|
|
-
|
467
|
|
- const _BottomWidget({
|
468
|
|
- Key key,
|
469
|
|
- this.onGalleryChange,
|
470
|
|
- this.options,
|
471
|
|
- this.provider,
|
472
|
|
- this.selectedProvider,
|
473
|
|
- this.galleryName = "",
|
474
|
|
- this.galleryListProvider,
|
475
|
|
- this.onTapPreview,
|
476
|
|
- }) : super(key: key);
|
477
|
|
-
|
478
|
|
- @override
|
479
|
|
- __BottomWidgetState createState() => __BottomWidgetState();
|
480
|
|
-}
|
481
|
|
-
|
482
|
|
-class __BottomWidgetState extends State<_BottomWidget> {
|
483
|
|
- Options get options => widget.options;
|
484
|
|
-
|
485
|
|
- I18nProvider get i18nProvider => widget.provider;
|
486
|
458
|
|
487
|
|
- @override
|
488
|
|
- Widget build(BuildContext context) {
|
489
|
|
- var textStyle = TextStyle(fontSize: 14.0);
|
490
|
|
- const textPadding = const EdgeInsets.symmetric(horizontal: 16.0);
|
491
|
|
- return Container(
|
492
|
|
- color: options.themeColor,
|
493
|
|
- child: SafeArea(
|
494
|
|
- bottom: true,
|
495
|
|
- top: false,
|
496
|
|
- child: Container(
|
497
|
|
- height: 52.0,
|
498
|
|
- child: Row(
|
499
|
|
- children: <Widget>[
|
500
|
|
- FlatButton(
|
501
|
|
- onPressed: _showGallerySelectDialog,
|
502
|
|
- splashColor: Colors.transparent,
|
503
|
|
- child: Container(
|
504
|
|
- alignment: Alignment.center,
|
505
|
|
- height: 44.0,
|
506
|
|
- padding: textPadding,
|
507
|
|
- child: Text(
|
508
|
|
- widget.galleryName,
|
509
|
|
- style: textStyle.copyWith(color: options.textColor),
|
510
|
|
- ),
|
511
|
|
- ),
|
512
|
|
- ),
|
513
|
|
- Expanded(
|
514
|
|
- child: Container(),
|
515
|
|
- ),
|
516
|
|
- FlatButton(
|
517
|
|
- onPressed: widget.onTapPreview,
|
518
|
|
- textColor: options.textColor,
|
519
|
|
- splashColor: Colors.transparent,
|
520
|
|
- disabledTextColor: options.disableColor,
|
521
|
|
- child: Container(
|
522
|
|
- height: 44.0,
|
523
|
|
- alignment: Alignment.center,
|
524
|
|
- child: Text(
|
525
|
|
- i18nProvider.getPreviewText(
|
526
|
|
- options, widget.selectedProvider),
|
527
|
|
- style: textStyle,
|
528
|
|
- ),
|
529
|
|
- padding: textPadding,
|
530
|
|
- ),
|
531
|
|
- ),
|
532
|
|
- ],
|
533
|
|
- ),
|
534
|
|
- ),
|
535
|
|
- ),
|
536
|
|
- );
|
537
|
|
- }
|
538
|
|
-
|
539
|
|
- void _showGallerySelectDialog() async {
|
540
|
|
- var result = await showModalBottomSheet(
|
541
|
|
- context: context,
|
542
|
|
- builder: (ctx) => ChangeGalleryDialog(
|
543
|
|
- galleryList: widget.galleryListProvider.galleryPathList,
|
544
|
|
- i18n: i18nProvider,
|
545
|
|
- options: options,
|
546
|
|
- ),
|
547
|
|
- );
|
548
|
|
-
|
549
|
|
- if (result != null) widget.onGalleryChange?.call(result);
|
550
|
|
- }
|
551
|
|
-}
|
552
|
|
-
|
553
|
|
-class ImageItem extends StatelessWidget {
|
554
|
|
- final AssetEntity entity;
|
555
|
|
-
|
556
|
|
- final Color themeColor;
|
557
|
|
-
|
558
|
|
- final int size;
|
559
|
|
-
|
560
|
|
- final LoadingDelegate loadingDelegate;
|
561
|
|
-
|
562
|
|
- final BadgeDelegate badgeDelegate;
|
563
|
|
-
|
564
|
|
- const ImageItem({
|
565
|
|
- Key key,
|
566
|
|
- this.entity,
|
567
|
|
- this.themeColor,
|
568
|
|
- this.size = 64,
|
569
|
|
- this.loadingDelegate,
|
570
|
|
- this.badgeDelegate,
|
571
|
|
- }) : super(key: key);
|
572
|
|
-
|
573
|
|
- @override
|
574
|
|
- Widget build(BuildContext context) {
|
575
|
|
- var thumb = ImageLruCache.getData(entity, size);
|
576
|
|
- if (thumb != null) {
|
577
|
|
- return _buildImageItem(context, thumb);
|
578
|
|
- }
|
579
|
|
-
|
580
|
|
- return FutureBuilder<Uint8List>(
|
581
|
|
- future: entity.thumbDataWithSize(size, size),
|
582
|
|
- builder: (BuildContext context, AsyncSnapshot<Uint8List> snapshot) {
|
583
|
|
- var futureData = snapshot.data;
|
584
|
|
- if (snapshot.connectionState == ConnectionState.done &&
|
585
|
|
- futureData != null) {
|
586
|
|
- ImageLruCache.setData(entity, size, futureData);
|
587
|
|
- return _buildImageItem(context, futureData);
|
588
|
|
- }
|
589
|
|
- return Center(
|
590
|
|
- child: loadingDelegate.buildPreviewLoading(
|
591
|
|
- context,
|
592
|
|
- entity,
|
593
|
|
- themeColor,
|
594
|
|
- ),
|
595
|
|
- );
|
596
|
|
- },
|
597
|
|
- );
|
598
|
|
- }
|
599
|
|
-
|
600
|
|
- Widget _buildImageItem(BuildContext context, Uint8List data) {
|
601
|
|
- var image = Image.memory(
|
602
|
|
- data,
|
603
|
|
- width: double.infinity,
|
604
|
|
- height: double.infinity,
|
605
|
|
- fit: BoxFit.cover,
|
606
|
|
- );
|
607
|
|
- // FutureBuilder()
|
608
|
|
- var badge = FutureBuilder<Duration>(
|
609
|
|
- future: entity.videoDuration,
|
610
|
|
- builder: (ctx, snapshot) {
|
611
|
|
- if (snapshot.hasData && snapshot != null) {
|
612
|
|
- var buildBadge =
|
613
|
|
- badgeDelegate?.buildBadge(context, entity.type, snapshot.data);
|
614
|
|
- if (buildBadge == null) {
|
615
|
|
- return Container();
|
616
|
|
- } else {
|
617
|
|
- return buildBadge;
|
618
|
|
- }
|
619
|
|
- } else {
|
620
|
|
- return Container();
|
621
|
|
- }
|
622
|
|
- },
|
623
|
|
- );
|
624
|
|
-
|
625
|
|
- return Stack(
|
626
|
|
- children: <Widget>[
|
627
|
|
- image,
|
628
|
|
- IgnorePointer(
|
629
|
|
- child: badge,
|
630
|
|
- ),
|
631
|
|
- ],
|
632
|
|
- );
|
633
|
|
- }
|
|
459
|
+ void _onAssetChange() {}
|
634
|
460
|
}
|