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

View file

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