Skip to content

Commit 07b932a

Browse files
authored
🐛 Fix behaviors when unselecting all assets in the viewer (#335)
* 🐛 Add confirm button enable check for preview * 💄 Correct the button's color * 📝 CHANGELOG
1 parent 6531041 commit 07b932a

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ that can be found in the LICENSE file. -->
1111
- Improve `onChangingSelected` in `AssetPickerViewerBuilderDelegate`. (#332)
1212
- Fix typo in `README.md`. (#333)
1313

14+
### Fixes
15+
16+
- Fix behaviors when unselecting all assets in the viewer.
17+
1418
## 7.3.1
1519

1620
### Improvements

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,8 @@ class DefaultAssetPickerBuilderDelegate
14591459
minWidth: p.isSelectedNotEmpty ? 48 : 20,
14601460
height: appBarItemHeight,
14611461
padding: const EdgeInsets.symmetric(horizontal: 12),
1462+
color: theme.colorScheme.secondary,
14621463
disabledColor: theme.dividerColor,
1463-
color: p.isSelectedNotEmpty ? themeColor : theme.dividerColor,
14641464
shape: RoundedRectangleBorder(
14651465
borderRadius: BorderRadius.circular(3),
14661466
),

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -790,48 +790,55 @@ class DefaultAssetPickerViewerBuilderDelegate
790790
'Viewer provider must not be null '
791791
'when the special type is not WeChat moment.',
792792
);
793+
Future<void> onPressed() async {
794+
if (isWeChatMoment && hasVideo) {
795+
Navigator.of(context).pop(<AssetEntity>[currentAsset]);
796+
return;
797+
}
798+
if (provider!.isSelectedNotEmpty) {
799+
Navigator.of(context).pop(provider.currentlySelectedAssets);
800+
return;
801+
}
802+
if (await onChangingSelected(context, currentAsset, false)) {
803+
Navigator.of(context).pop(
804+
selectedAssets ?? <AssetEntity>[currentAsset],
805+
);
806+
}
807+
}
808+
809+
String buildText() {
810+
if (isWeChatMoment && hasVideo) {
811+
return textDelegate.confirm;
812+
}
813+
if (provider!.isSelectedNotEmpty) {
814+
return '${textDelegate.confirm}'
815+
' (${provider.currentlySelectedAssets.length}'
816+
'/'
817+
'${selectorProvider!.maxAssets})';
818+
}
819+
return textDelegate.confirm;
820+
}
821+
822+
final bool isButtonEnabled = provider == null ||
823+
provider.currentlySelectedAssets.isNotEmpty ||
824+
previewAssets.isEmpty ||
825+
selectedNotifier.value == 0;
793826
return MaterialButton(
794-
minWidth: () {
795-
if (isWeChatMoment && hasVideo) {
796-
return 48.0;
797-
}
798-
return provider!.isSelectedNotEmpty ? 48.0 : 20.0;
799-
}(),
800-
height: 32.0,
801-
padding: const EdgeInsets.symmetric(horizontal: 12.0),
827+
minWidth:
828+
(isWeChatMoment && hasVideo) || provider!.isSelectedNotEmpty
829+
? 48
830+
: 20,
831+
height: 32,
832+
padding: const EdgeInsets.symmetric(horizontal: 12),
802833
color: themeData.colorScheme.secondary,
834+
disabledColor: themeData.dividerColor,
803835
shape: RoundedRectangleBorder(
804-
borderRadius: BorderRadius.circular(3.0),
836+
borderRadius: BorderRadius.circular(3),
805837
),
806-
onPressed: () async {
807-
if (isWeChatMoment && hasVideo) {
808-
Navigator.of(context).pop(<AssetEntity>[currentAsset]);
809-
return;
810-
}
811-
if (provider!.isSelectedNotEmpty) {
812-
Navigator.of(context).pop(provider.currentlySelectedAssets);
813-
return;
814-
}
815-
if (await onChangingSelected(context, currentAsset, false)) {
816-
Navigator.of(context).pop(
817-
selectedAssets ?? <AssetEntity>[currentAsset],
818-
);
819-
}
820-
},
838+
onPressed: isButtonEnabled ? onPressed : null,
821839
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
822840
child: ScaleText(
823-
() {
824-
if (isWeChatMoment && hasVideo) {
825-
return textDelegate.confirm;
826-
}
827-
if (provider!.isSelectedNotEmpty) {
828-
return '${textDelegate.confirm}'
829-
' (${provider.currentlySelectedAssets.length}'
830-
'/'
831-
'${selectorProvider!.maxAssets})';
832-
}
833-
return textDelegate.confirm;
834-
}(),
841+
buildText(),
835842
style: TextStyle(
836843
color: themeData.textTheme.bodyText1?.color,
837844
fontSize: 17,

0 commit comments

Comments
 (0)