|
@@ -1,8 +1,8 @@
|
1
|
1
|
// Copyright (c) 2018, the Zefyr project authors. Please see the AUTHORS file
|
2
|
2
|
// for details. All rights reserved. Use of this source code is governed by a
|
3
|
3
|
// BSD-style license that can be found in the LICENSE file.
|
|
4
|
+import 'dart:async';
|
4
|
5
|
import 'dart:io';
|
5
|
|
-import 'dart:typed_data';
|
6
|
6
|
|
7
|
7
|
import 'package:flutter/material.dart';
|
8
|
8
|
import 'package:flutter/services.dart';
|
|
@@ -437,6 +437,9 @@ class ImageButton extends StatefulWidget {
|
437
|
437
|
}
|
438
|
438
|
|
439
|
439
|
class _ImageButtonState extends State<ImageButton> {
|
|
440
|
+
|
|
441
|
+ List<AssetEntity> pickedAssetList = [];
|
|
442
|
+
|
440
|
443
|
@override
|
441
|
444
|
Widget build(BuildContext context) {
|
442
|
445
|
final toolbar = ZefyrToolbar.of(context);
|
|
@@ -464,6 +467,7 @@ class _ImageButtonState extends State<ImageButton> {
|
464
|
467
|
Widget buildOverlay(BuildContext context) {
|
465
|
468
|
final theme = ZefyrTheme.of(context).toolbarTheme;
|
466
|
469
|
final toolbar = ZefyrToolbar.of(context);
|
|
470
|
+ final pickedChangeController = StreamController<List<AssetEntity>>.broadcast();
|
467
|
471
|
return Material(
|
468
|
472
|
color: theme.color,
|
469
|
473
|
child: Container(
|
|
@@ -527,8 +531,17 @@ class _ImageButtonState extends State<ImageButton> {
|
527
|
531
|
sortDelegate: SortDelegate.common,
|
528
|
532
|
pickType: PickType.onlyImage,
|
529
|
533
|
photoPathList: null,
|
530
|
|
- ).then((List<AssetEntity> imgList) {
|
531
|
|
-
|
|
534
|
+ ).then((List<AssetEntity> entity) async {
|
|
535
|
+ if (entity.isNotEmpty) {
|
|
536
|
+ toolbar.closeOverlay();
|
|
537
|
+ final editor = ZefyrToolbar.of(context).editor;
|
|
538
|
+ for (var asset in entity) {
|
|
539
|
+ final image = await editor.imageDelegate.picked(asset);
|
|
540
|
+ if (image != null) {
|
|
541
|
+ editor.formatSelection(NotusAttribute.embed.image(image));
|
|
542
|
+ }
|
|
543
|
+ }
|
|
544
|
+ }
|
532
|
545
|
});
|
533
|
546
|
},
|
534
|
547
|
child: Container(
|
|
@@ -565,15 +578,25 @@ class _ImageButtonState extends State<ImageButton> {
|
565
|
578
|
toolbar.editor.tapHandle = TapHandle.previewImage;
|
566
|
579
|
},
|
567
|
580
|
child: PhotoPicker.buildGallery(
|
568
|
|
- context: context,
|
569
|
|
- padding: 4,
|
570
|
|
- thumbSize: 300,
|
571
|
|
- itemRadio: 0.5,
|
572
|
|
- provider: I18nProvider.chinese,
|
573
|
|
- sortDelegate: SortDelegate.common,
|
574
|
|
- pickType: PickType.onlyImage,
|
575
|
|
- photoPathList: null,
|
576
|
|
- ),
|
|
581
|
+ context: context,
|
|
582
|
+ padding: 4,
|
|
583
|
+ thumbSize: 300,
|
|
584
|
+ itemRadio: 0.5,
|
|
585
|
+ provider: I18nProvider.chinese,
|
|
586
|
+ sortDelegate: SortDelegate.common,
|
|
587
|
+ pickType: PickType.onlyImage,
|
|
588
|
+ photoPathList: null,
|
|
589
|
+ onSelected: (List<AssetEntity> entity) {
|
|
590
|
+ pickedChangeController.add(entity);
|
|
591
|
+ }
|
|
592
|
+ ),
|
|
593
|
+ // StreamBuilder<List<AssetEntity>>(
|
|
594
|
+ // stream: pickedChangeController.stream,
|
|
595
|
+ // initialData: [],
|
|
596
|
+ // builder: (context, snapshot) {
|
|
597
|
+ // return
|
|
598
|
+ // },
|
|
599
|
+ // ),
|
577
|
600
|
),
|
578
|
601
|
),
|
579
|
602
|
],
|
|
@@ -584,52 +607,67 @@ class _ImageButtonState extends State<ImageButton> {
|
584
|
607
|
height: 50,
|
585
|
608
|
color: theme.color,
|
586
|
609
|
padding: EdgeInsets.symmetric(horizontal: 20),
|
587
|
|
- child: Row(
|
588
|
|
- children: [
|
589
|
|
- Expanded(
|
590
|
|
- child: Row(
|
591
|
|
- children: [
|
592
|
|
- SizedBox(
|
593
|
|
- width: 16,
|
594
|
|
- height: 16,
|
595
|
|
- child: Radio<bool>(
|
596
|
|
- value: false,
|
597
|
|
- groupValue: false,
|
598
|
|
- onChanged: (bool result) {},
|
599
|
|
- ),
|
|
610
|
+ child: StreamBuilder(
|
|
611
|
+ builder: (context, snapshot) {
|
|
612
|
+ return Row(
|
|
613
|
+ children: [
|
|
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) {},
|
|
624
|
+ ),
|
|
625
|
+ ),
|
|
626
|
+ Padding(
|
|
627
|
+ padding: EdgeInsets.symmetric(horizontal: 8),
|
|
628
|
+ child: Text(
|
|
629
|
+ '原图',
|
|
630
|
+ style: TextStyle(color: theme.iconColor, fontSize: 16),
|
|
631
|
+ ),
|
|
632
|
+ ),
|
|
633
|
+ ],
|
600
|
634
|
),
|
601
|
|
- Padding(
|
602
|
|
- padding: EdgeInsets.symmetric(horizontal: 8),
|
|
635
|
+ ),
|
|
636
|
+ FlatButton(
|
|
637
|
+ padding: EdgeInsets.zero,
|
|
638
|
+ color: theme.toggleColor,
|
|
639
|
+ disabledColor: theme.disabledIconColor,
|
|
640
|
+ shape: StadiumBorder(),
|
|
641
|
+ onPressed: snapshot.data.isNotEmpty ? () async {
|
|
642
|
+ pickedChangeController.add([]);
|
|
643
|
+ toolbar.closeOverlay();
|
|
644
|
+ for (var asset in snapshot.data) {
|
|
645
|
+ final image = await toolbar.editor.imageDelegate.picked(asset);
|
|
646
|
+ if (image != null) {
|
|
647
|
+ toolbar.editor.formatSelection(NotusAttribute.embed.image(image));
|
|
648
|
+ }
|
|
649
|
+ }
|
|
650
|
+ } : null,
|
|
651
|
+ child: Container(
|
|
652
|
+ height: 30,
|
|
653
|
+ alignment: Alignment.center,
|
|
654
|
+ padding: EdgeInsets.symmetric(horizontal: 20),
|
603
|
655
|
child: Text(
|
604
|
|
- '原图',
|
605
|
|
- style:
|
606
|
|
- TextStyle(color: theme.iconColor, fontSize: 16),
|
|
656
|
+ '上传 (${snapshot.data.length})',
|
|
657
|
+ style: TextStyle(
|
|
658
|
+ color: Colors.white,
|
|
659
|
+ fontSize: 14,
|
|
660
|
+ ),
|
|
661
|
+ ),
|
607
|
662
|
),
|
608
|
663
|
),
|
609
|
|
- ],
|
610
|
|
- ),
|
611
|
|
- ),
|
612
|
|
- FlatButton(
|
613
|
|
- padding: EdgeInsets.zero,
|
614
|
|
- color: theme.toggleColor,
|
615
|
|
- shape: StadiumBorder(),
|
616
|
|
- onPressed: () {},
|
617
|
|
- child: Container(
|
618
|
|
- height: 30,
|
619
|
|
- alignment: Alignment.center,
|
620
|
|
- padding: EdgeInsets.symmetric(horizontal: 20),
|
621
|
|
- child: Text(
|
622
|
|
- '上传 (2)',
|
623
|
|
- style: TextStyle(
|
624
|
|
- color: Colors.white,
|
625
|
|
- fontSize: 14,
|
626
|
|
- ),
|
627
|
|
- ),
|
628
|
|
- ),
|
629
|
|
- ),
|
630
|
|
- ],
|
|
664
|
+ ],
|
|
665
|
+ );
|
|
666
|
+ },
|
|
667
|
+ initialData: [],
|
|
668
|
+ stream: pickedChangeController.stream,
|
631
|
669
|
),
|
632
|
|
- )
|
|
670
|
+ ),
|
633
|
671
|
],
|
634
|
672
|
),
|
635
|
673
|
),
|
|
@@ -647,10 +685,11 @@ class _ImageButtonState extends State<ImageButton> {
|
647
|
685
|
|
648
|
686
|
void _pickFromGallery() async {
|
649
|
687
|
final editor = ZefyrToolbar.of(context).editor;
|
650
|
|
- final image = await editor.imageDelegate
|
651
|
|
- .pickImage(editor.imageDelegate.gallerySource);
|
652
|
|
- if (image != null) {
|
653
|
|
- editor.formatSelection(NotusAttribute.embed.image(image));
|
|
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
|
+ }
|
654
|
693
|
}
|
655
|
694
|
}
|
656
|
695
|
}
|