Migrate WillPopScope where we could

This commit is contained in:
Ming Ming 2024-05-23 01:06:08 +08:00
parent 8512ec0c4d
commit bc690dc61e
3 changed files with 195 additions and 188 deletions

View file

@ -143,16 +143,17 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_bloc.state.isEditMode) {
return _BlocBuilder(
buildWhen: (previous, current) =>
previous.isEditMode != current.isEditMode ||
previous.selectedItems.isEmpty != current.selectedItems.isEmpty,
builder: (context, state) => PopScope(
canPop: !state.isEditMode && state.selectedItems.isEmpty,
onPopInvoked: (didPop) {
if (state.isEditMode) {
_bloc.add(const _CancelEdit());
return false;
} else if (_bloc.state.selectedItems.isNotEmpty) {
} else if (state.selectedItems.isNotEmpty) {
_bloc.add(const _SetSelectedItems(items: {}));
return false;
} else {
return true;
}
},
child: Scaffold(
@ -185,7 +186,8 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
if (state.importResult != null) {
Navigator.of(context).pushReplacementNamed(
CollectionBrowser.routeName,
arguments: CollectionBrowserArguments(state.importResult!),
arguments:
CollectionBrowserArguments(state.importResult!),
);
}
},
@ -202,8 +204,8 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
if (canSort &&
!SessionStorage().hasShowDragRearrangeNotification) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(L10n.global().albumEditDragRearrangeNotification),
content: Text(
L10n.global().albumEditDragRearrangeNotification),
duration: k.snackBarDurationNormal,
));
SessionStorage().hasShowDragRearrangeNotification = true;
@ -216,7 +218,8 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
if (error != null && isPageVisible()) {
final String content;
if (error.error is _ArchiveFailedError) {
content = L10n.global().archiveSelectedFailureNotification(
content = L10n.global()
.archiveSelectedFailureNotification(
(error.error as _ArchiveFailedError).count);
} else if (error.error is _RemoveFailedError) {
content = L10n.global().deleteSelectedFailureNotification(
@ -338,6 +341,7 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
),
),
),
),
);
}

View file

@ -128,10 +128,12 @@ class _ImageEditorState extends State<ImageEditor> {
}
Widget _buildContent(BuildContext context) {
return WillPopScope(
onWillPop: () async {
unawaited(_onBackButton(context));
return false;
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
_onBackButton(context);
}
},
child: ColoredBox(
color: Colors.black,

View file

@ -28,6 +28,7 @@ abstract class SelectableItem {
StaggeredTile get staggeredTile => const StaggeredTile.count(1, 1);
}
@Deprecated("Use SelectableItemList widget")
mixin SelectableItemStreamListMixin<T extends StatefulWidget> on State<T> {
@override
initState() {