@@ -455,12 +455,15 @@ class DefaultAssetPickerBuilderDelegate
455
455
/// The current special picker type for the picker.
456
456
/// 当前特殊选择类型
457
457
///
458
- /// There're several types which are special:
458
+ /// Several types which are special:
459
459
/// * [SpecialPickerType.wechatMoment] When user selected video, no more images
460
460
/// can be selected.
461
+ /// * [SpecialPickerType.noPreview] Disable preview of asset; Clicking on an
462
+ /// asset selects it.
461
463
///
462
464
/// 这里包含一些特殊选择类型:
463
465
/// * [SpecialPickerType.wechatMoment] 微信朋友圈模式。当用户选择了视频,将不能选择图片。
466
+ /// * [SpecialPickerType.noPreview] 禁用资源预览。多选时单击资产将直接选中,单选时选中并返回。
464
467
final SpecialPickerType ? specialPickerType;
465
468
466
469
/// [Duration] when triggering path switching.
@@ -471,6 +474,10 @@ class DefaultAssetPickerBuilderDelegate
471
474
/// 切换路径时的动画曲线
472
475
Curve get switchingPathCurve => Curves .easeInOut;
473
476
477
+ /// Whether the preview of assets is enabled.
478
+ /// 资源的预览是否启用
479
+ bool get isPreviewEnabled => specialPickerType != SpecialPickerType .noPreview;
480
+
474
481
@override
475
482
Widget androidLayout (BuildContext context) {
476
483
return FixedAppBarWrapper (
@@ -491,7 +498,8 @@ class DefaultAssetPickerBuilderDelegate
491
498
child: Column (
492
499
children: < Widget > [
493
500
Expanded (child: assetsGridBuilder (context)),
494
- if (! isSingleAssetMode) bottomActionBar (context),
501
+ if (! isSingleAssetMode && isPreviewEnabled)
502
+ bottomActionBar (context),
495
503
],
496
504
),
497
505
),
@@ -513,7 +521,9 @@ class DefaultAssetPickerBuilderDelegate
513
521
centerTitle: isAppleOS,
514
522
title: pathEntitySelector (context),
515
523
leading: backButton (context),
516
- actions: ! isAppleOS ? < Widget > [confirmButton (context)] : null ,
524
+ actions: ! isAppleOS && (isPreviewEnabled || ! isSingleAssetMode)
525
+ ? < Widget > [confirmButton (context)]
526
+ : null ,
517
527
actionsPadding: const EdgeInsets .only (right: 14.0 ),
518
528
blurRadius: isAppleOS ? appleOSBlurRadius : 0.0 ,
519
529
);
@@ -537,7 +547,8 @@ class DefaultAssetPickerBuilderDelegate
537
547
Positioned .fill (
538
548
child: assetsGridBuilder (context),
539
549
),
540
- if (! isSingleAssetMode || isAppleOS)
550
+ if ((! isSingleAssetMode || isAppleOS) &&
551
+ isPreviewEnabled)
541
552
PositionedDirectional (
542
553
bottom: 0.0 ,
543
554
child: bottomActionBar (context),
@@ -1148,63 +1159,67 @@ class DefaultAssetPickerBuilderDelegate
1148
1159
);
1149
1160
final bool selected = selectedAssets.contains (asset);
1150
1161
final double indicatorSize = Screens .width / gridCount / 3 ;
1151
- return Positioned (
1152
- top: 0.0 ,
1153
- right: 0.0 ,
1154
- child: GestureDetector (
1155
- behavior: HitTestBehavior .opaque,
1156
- onTap: () {
1157
- if (selected) {
1158
- provider.unSelectAsset (asset);
1159
- } else {
1160
- if (isSingleAssetMode) {
1161
- provider.selectedAssets.clear ();
1162
- }
1163
- provider.selectAsset (asset);
1162
+ final Widget innerSelector = AnimatedContainer (
1163
+ duration: switchingPathDuration,
1164
+ width: indicatorSize / (isAppleOS ? 1.25 : 1.5 ),
1165
+ height: indicatorSize / (isAppleOS ? 1.25 : 1.5 ),
1166
+ decoration: BoxDecoration (
1167
+ border:
1168
+ ! selected ? Border .all (color: Colors .white, width: 2.0 ) : null ,
1169
+ color: selected ? themeColor : null ,
1170
+ shape: BoxShape .circle,
1171
+ ),
1172
+ child: AnimatedSwitcher (
1173
+ duration: switchingPathDuration,
1174
+ reverseDuration: switchingPathDuration,
1175
+ child: selected
1176
+ ? isSingleAssetMode
1177
+ ? const Icon (Icons .check, size: 18.0 )
1178
+ : Text (
1179
+ '${selectedAssets .indexOf (asset ) + 1 }' ,
1180
+ style: TextStyle (
1181
+ color: selected
1182
+ ? theme.textTheme.bodyText1? .color
1183
+ : null ,
1184
+ fontSize: isAppleOS ? 16.0 : 14.0 ,
1185
+ fontWeight:
1186
+ isAppleOS ? FontWeight .w600 : FontWeight .bold,
1187
+ ),
1188
+ )
1189
+ : const SizedBox .shrink (),
1190
+ ),
1191
+ );
1192
+ final GestureDetector selectorWidget = GestureDetector (
1193
+ behavior: HitTestBehavior .opaque,
1194
+ onTap: () {
1195
+ if (selected) {
1196
+ provider.unSelectAsset (asset);
1197
+ } else {
1198
+ if (isSingleAssetMode) {
1199
+ provider.selectedAssets.clear ();
1164
1200
}
1165
- },
1166
- child: Container (
1167
- margin: EdgeInsets .all (
1168
- Screens .width / gridCount / (isAppleOS ? 12.0 : 15.0 ),
1169
- ),
1170
- width: indicatorSize,
1171
- height: indicatorSize,
1172
- alignment: AlignmentDirectional .topEnd,
1173
- child: AnimatedContainer (
1174
- duration: switchingPathDuration,
1175
- width: indicatorSize / (isAppleOS ? 1.25 : 1.5 ),
1176
- height: indicatorSize / (isAppleOS ? 1.25 : 1.5 ),
1177
- decoration: BoxDecoration (
1178
- border: ! selected
1179
- ? Border .all (color: Colors .white, width: 2.0 )
1180
- : null ,
1181
- color: selected ? themeColor : null ,
1182
- shape: BoxShape .circle,
1183
- ),
1184
- child: AnimatedSwitcher (
1185
- duration: switchingPathDuration,
1186
- reverseDuration: switchingPathDuration,
1187
- child: selected
1188
- ? isSingleAssetMode
1189
- ? const Icon (Icons .check, size: 18.0 )
1190
- : Text (
1191
- '${selectedAssets .indexOf (asset ) + 1 }' ,
1192
- style: TextStyle (
1193
- color: selected
1194
- ? theme.textTheme.bodyText1? .color
1195
- : null ,
1196
- fontSize: isAppleOS ? 16.0 : 14.0 ,
1197
- fontWeight: isAppleOS
1198
- ? FontWeight .w600
1199
- : FontWeight .bold,
1200
- ),
1201
- )
1202
- : const SizedBox .shrink (),
1203
- ),
1204
- ),
1201
+ provider.selectAsset (asset);
1202
+ if (isSingleAssetMode && ! isPreviewEnabled) {
1203
+ Navigator .of (context).pop (provider.selectedAssets);
1204
+ }
1205
+ }
1206
+ },
1207
+ child: Container (
1208
+ margin: EdgeInsets .all (
1209
+ Screens .width / gridCount / (isAppleOS ? 12.0 : 15.0 ),
1205
1210
),
1211
+ width: isPreviewEnabled ? indicatorSize : null ,
1212
+ height: isPreviewEnabled ? indicatorSize : null ,
1213
+ alignment: AlignmentDirectional .topEnd,
1214
+ child: (! isPreviewEnabled && isSingleAssetMode && ! selected)
1215
+ ? const SizedBox .shrink ()
1216
+ : innerSelector,
1206
1217
),
1207
1218
);
1219
+ if (isPreviewEnabled) {
1220
+ return Positioned (top: 0.0 , right: 0.0 , child: selectorWidget);
1221
+ }
1222
+ return selectorWidget;
1208
1223
},
1209
1224
);
1210
1225
}
@@ -1214,9 +1229,9 @@ class DefaultAssetPickerBuilderDelegate
1214
1229
return Positioned .fill (
1215
1230
child: GestureDetector (
1216
1231
onTap: () async {
1217
- // While the special type is WeChat moment, picture and video cannot
1232
+ // When the special type is WeChat Moment, pictures and videos cannot
1218
1233
// be selected at the same time. Video select should be banned if any
1219
- // picture is selected.
1234
+ // pictures are selected.
1220
1235
if (specialPickerType == SpecialPickerType .wechatMoment &&
1221
1236
asset.type == AssetType .video &&
1222
1237
provider.selectedAssets.isNotEmpty) {
0 commit comments