lucky1213 4 лет назад
Родитель
Сommit
c6b9ee0129

+ 2
- 1
packages/zefyr/example/lib/src/images.dart Просмотреть файл

@@ -41,7 +41,8 @@ class CustomImageDelegate implements ZefyrImageDelegate<ImageSource> {
41 41
   }
42 42
 
43 43
   @override
44
-  Future<String> picked(asset) async {
44
+  Future<String> picked(asset, isFullImage) async {
45
+    print(isFullImage);
45 46
     File file = await asset.file;
46 47
     return file.uri.toString();
47 48
   }

+ 76
- 54
packages/zefyr/lib/src/widgets/buttons.dart Просмотреть файл

@@ -467,7 +467,7 @@ class _ImageButtonState extends State<ImageButton> {
467 467
   Widget buildOverlay(BuildContext context) {
468 468
     final theme = ZefyrTheme.of(context).toolbarTheme;
469 469
     final toolbar = ZefyrToolbar.of(context);
470
-    final pickedChangeController = StreamController<List<AssetEntity>>.broadcast();
470
+    final pickedChangeController = StreamController<PickedEntity>.broadcast();
471 471
     return Material(
472 472
       color: theme.color,
473 473
       child: Container(
@@ -531,12 +531,12 @@ class _ImageButtonState extends State<ImageButton> {
531 531
                                     sortDelegate: SortDelegate.common,
532 532
                                     pickType: PickType.onlyImage,
533 533
                                     photoPathList: null,
534
-                                  ).then((List<AssetEntity> entity) async {
535
-                                    if (entity.isNotEmpty) {
534
+                                  ).then((PickedEntity entity) async {
535
+                                    if (entity.asset.isNotEmpty) {
536 536
                                       toolbar.closeOverlay();
537 537
                                       final editor = ZefyrToolbar.of(context).editor;
538
-                                      for (var asset in entity) {
539
-                                        final image = await editor.imageDelegate.picked(asset);
538
+                                      for (var asset in entity.asset) {
539
+                                        final image = await editor.imageDelegate.picked(asset, entity.isFullImage);
540 540
                                         if (image != null) {
541 541
                                           editor.formatSelection(NotusAttribute.embed.image(image));
542 542
                                         }
@@ -577,7 +577,11 @@ class _ImageButtonState extends State<ImageButton> {
577 577
                         onPointerUp: (PointerUpEvent event) {
578 578
                           toolbar.editor.tapHandle = TapHandle.previewImage;
579 579
                         },
580
-                        child: PhotoPicker.buildGallery(
580
+                        child: StreamBuilder<PickedEntity>(
581
+                          stream: pickedChangeController.stream,
582
+                          initialData: PickedEntity(),
583
+                          builder: (context, snapshot) {
584
+                            return PhotoPicker.buildGallery(
581 585
                               context: context,
582 586
                               padding: 4,
583 587
                               thumbSize: 300,
@@ -586,17 +590,13 @@ class _ImageButtonState extends State<ImageButton> {
586 590
                               sortDelegate: SortDelegate.common,
587 591
                               pickType: PickType.onlyImage,
588 592
                               photoPathList: null,
589
-                              onSelected: (List<AssetEntity> entity) {
593
+                              isFullImage: snapshot.data.isFullImage,
594
+                              onSelected: (PickedEntity entity) {
590 595
                                 pickedChangeController.add(entity);
591 596
                               }
592
-                            ),
593
-                        // StreamBuilder<List<AssetEntity>>(
594
-                        //   stream: pickedChangeController.stream,
595
-                        //   initialData: [],
596
-                        //   builder: (context, snapshot) {
597
-                        //     return 
598
-                        //   },
599
-                        // ),
597
+                            );
598
+                          },
599
+                        ),
600 600
                       ),
601 601
                     ),
602 602
                   ],
@@ -607,27 +607,49 @@ class _ImageButtonState extends State<ImageButton> {
607 607
               height: 50,
608 608
               color: theme.color,
609 609
               padding: EdgeInsets.symmetric(horizontal: 20),
610
-              child: StreamBuilder(
610
+              child: StreamBuilder<PickedEntity>(
611 611
                 builder: (context, snapshot) {
612 612
                   return Row(
613 613
                     children: [
614 614
                       Expanded(
615
-                        child: Row(
616
-                          children: [
617
-                            SizedBox(
618
-                              width: 16,
619
-                              height: 16,
620
-                              child: Radio<bool>(
621
-                                value: false,
622
-                                groupValue: false,
623
-                                onChanged: (bool result) {},
615
+                        child: Stack(
616
+                          children: <Widget>[
617
+                            IgnorePointer(
618
+                              child: Row(
619
+                                children: [
620
+                                  SizedBox(
621
+                                    width: 16,
622
+                                    height: 16,
623
+                                    child: Radio<bool>(
624
+                                      value: true,
625
+                                      groupValue: snapshot.data.isFullImage,
626
+                                      onChanged: (bool result) {},
627
+                                    ),
628
+                                  ),
629
+                                  Padding(
630
+                                    padding: EdgeInsets.symmetric(horizontal: 8),
631
+                                    child: Text(
632
+                                      '原图',
633
+                                      style: TextStyle(color: theme.iconColor, fontSize: 16),
634
+                                    ),
635
+                                  ),
636
+                                ],
624 637
                               ),
625 638
                             ),
626
-                            Padding(
627
-                              padding: EdgeInsets.symmetric(horizontal: 8),
628
-                              child: Text(
629
-                                '原图',
630
-                                style: TextStyle(color: theme.iconColor, fontSize: 16),
639
+                            Positioned(
640
+                              top: 0.0,
641
+                              bottom: 0.0,
642
+                              left: 0.0,
643
+                              right: 0.0,
644
+                              child: GestureDetector(
645
+                                onTap: () {
646
+                                  pickedChangeController.add(PickedEntity(
647
+                                    asset: snapshot.data.asset,
648
+                                    isFullImage: !snapshot.data.isFullImage,
649
+                                  ));
650
+                                },
651
+                                behavior: HitTestBehavior.translucent,
652
+                                child: Container(),
631 653
                               ),
632 654
                             ),
633 655
                           ],
@@ -638,11 +660,11 @@ class _ImageButtonState extends State<ImageButton> {
638 660
                         color: theme.toggleColor,
639 661
                         disabledColor: theme.disabledIconColor,
640 662
                         shape: StadiumBorder(),
641
-                        onPressed: snapshot.data.isNotEmpty ? () async {
642
-                          pickedChangeController.add([]);
663
+                        onPressed: snapshot.data.asset.isNotEmpty ? () async {
664
+                          pickedChangeController.add(PickedEntity());
643 665
                           toolbar.closeOverlay();
644
-                          for (var asset in snapshot.data) {
645
-                            final image = await toolbar.editor.imageDelegate.picked(asset);
666
+                          for (var asset in snapshot.data.asset) {
667
+                            final image = await toolbar.editor.imageDelegate.picked(asset, snapshot.data.isFullImage);
646 668
                             if (image != null) {
647 669
                               toolbar.editor.formatSelection(NotusAttribute.embed.image(image));
648 670
                             }
@@ -653,7 +675,7 @@ class _ImageButtonState extends State<ImageButton> {
653 675
                           alignment: Alignment.center,
654 676
                           padding: EdgeInsets.symmetric(horizontal: 20),
655 677
                           child: Text(
656
-                              '上传 (${snapshot.data.length})',
678
+                              '上传 ${snapshot.data.asset.isNotEmpty ? "(${snapshot.data.asset.length})" : ''}',
657 679
                               style: TextStyle(
658 680
                                 color: Colors.white,
659 681
                                 fontSize: 14,
@@ -664,7 +686,7 @@ class _ImageButtonState extends State<ImageButton> {
664 686
                     ],
665 687
                   );
666 688
                 },
667
-                initialData: [],
689
+                initialData: PickedEntity(),
668 690
                 stream: pickedChangeController.stream,
669 691
               ),
670 692
             ),
@@ -674,24 +696,24 @@ class _ImageButtonState extends State<ImageButton> {
674 696
     );
675 697
   }
676 698
 
677
-  void _pickFromCamera() async {
678
-    final editor = ZefyrToolbar.of(context).editor;
679
-    final image =
680
-        await editor.imageDelegate.pickImage(editor.imageDelegate.cameraSource);
681
-    if (image != null) {
682
-      editor.formatSelection(NotusAttribute.embed.image(image));
683
-    }
684
-  }
685
-
686
-  void _pickFromGallery() async {
687
-    final editor = ZefyrToolbar.of(context).editor;
688
-    for (var asset in pickedAssetList) {
689
-      final image = await editor.imageDelegate.picked(asset);
690
-      if (image != null) {
691
-        editor.formatSelection(NotusAttribute.embed.image(image));
692
-      }
693
-    }
694
-  }
699
+  // void _pickFromCamera() async {
700
+  //   final editor = ZefyrToolbar.of(context).editor;
701
+  //   final image =
702
+  //       await editor.imageDelegate.pickImage(editor.imageDelegate.cameraSource);
703
+  //   if (image != null) {
704
+  //     editor.formatSelection(NotusAttribute.embed.image(image));
705
+  //   }
706
+  // }
707
+
708
+  // void _pickFromGallery() async {
709
+  //   final editor = ZefyrToolbar.of(context).editor;
710
+  //   for (var asset in pickedAssetList) {
711
+  //     final image = await editor.imageDelegate.picked(asset);
712
+  //     if (image != null) {
713
+  //       editor.formatSelection(NotusAttribute.embed.image(image));
714
+  //     }
715
+  //   }
716
+  // }
695 717
 }
696 718
 
697 719
 class LinkButton extends StatefulWidget {

+ 1
- 1
packages/zefyr/lib/src/widgets/image.dart Просмотреть файл

@@ -40,7 +40,7 @@ abstract class ZefyrImageDelegate<S> {
40 40
   /// by a file hosting service like AWS S3 or Google Drive.
41 41
   Future<String> pickImage(S source);
42 42
 
43
-  Future<String> picked(AssetEntity list);
43
+  Future<String> picked(AssetEntity list, bool isFullImage);
44 44
 }
45 45
 
46 46
 class ZefyrImage extends StatefulWidget {

+ 1
- 1
packages/zefyr/test/widgets/buttons_test.dart Просмотреть файл

@@ -201,7 +201,7 @@ class _TestImageDelegate implements ZefyrImageDelegate<String> {
201 201
   }
202 202
 
203 203
   @override
204
-  Future<String> picked(list) async {
204
+  Future<String> picked(list, isFull) async {
205 205
     return Future.value("file:///tmp/test.jpg");
206 206
   }
207 207
 }

+ 1
- 1
packages/zefyr/test/widgets/image_test.dart Просмотреть файл

@@ -105,7 +105,7 @@ class _TestImageDelegate implements ZefyrImageDelegate<String> {
105 105
   }
106 106
 
107 107
   @override
108
-  Future<String> picked(asset) async {
108
+  Future<String> picked(asset, isFull) async {
109 109
     return Future.value("file:///tmp/test.jpg");
110 110
   }
111 111
 }

+ 1
- 1
packages/zefyr/test/widgets/scope_test.dart Просмотреть файл

@@ -92,7 +92,7 @@ class _TestImageDelegate implements ZefyrImageDelegate<String> {
92 92
   }
93 93
 
94 94
   @override
95
-  Future<String> picked(asset) async {
95
+  Future<String> picked(asset, isFull) async {
96 96
     return null;
97 97
   }
98 98
 }