fix: crash on delete button press caused by GoRouter (#6629)

* fix: crash on delete button press caused by GoRouter

* fix: gorouter pop
This commit is contained in:
rensawamo 2024-10-28 10:09:11 +09:00 committed by GitHub
parent a42b6e02ab
commit eafd0b3353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 60 deletions

View File

@ -9,7 +9,6 @@ import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/plugins/shared/share/publish_name_generator.dart'; import 'package:appflowy/plugins/shared/share/publish_name_generator.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart'; import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/navigator_context_exntesion.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart'; import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart'; import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart'; import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
@ -24,10 +23,15 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
const MobileViewPageMoreBottomSheet({super.key, required this.view}); const MobileViewPageMoreBottomSheet({super.key, required this.view});
final ViewPB view; final ViewPB view;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ViewPageBottomSheet( return BlocListener<ViewBloc, ViewState>(
listener: (context, state) {
if (state.successOrFailure.isSuccess && state.isDeleted) {
context.go('/home');
}
},
child: ViewPageBottomSheet(
view: view, view: view,
onAction: (action) async { onAction: (action) async {
switch (action) { switch (action) {
@ -37,7 +41,7 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
break; break;
case MobileViewBottomSheetBodyAction.delete: case MobileViewBottomSheetBodyAction.delete:
context.read<ViewBloc>().add(const ViewEvent.delete()); context.read<ViewBloc>().add(const ViewEvent.delete());
context.popToHome(); context.pop();
break; break;
case MobileViewBottomSheetBodyAction.addToFavorites: case MobileViewBottomSheetBodyAction.addToFavorites:
case MobileViewBottomSheetBodyAction.removeFromFavorites: case MobileViewBottomSheetBodyAction.removeFromFavorites:
@ -87,6 +91,7 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
_onRename(context, name); _onRename(context, name);
context.pop(); context.pop();
}, },
),
); );
} }

View File

@ -154,6 +154,7 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
(l) { (l) {
return state.copyWith( return state.copyWith(
successOrFailure: FlowyResult.success(null), successOrFailure: FlowyResult.success(null),
isDeleted: true,
); );
}, },
(error) => state.copyWith( (error) => state.copyWith(
@ -478,6 +479,7 @@ class ViewState with _$ViewState {
required bool isEditing, required bool isEditing,
required bool isExpanded, required bool isExpanded,
required FlowyResult<void, FlowyError> successOrFailure, required FlowyResult<void, FlowyError> successOrFailure,
@Default(false) bool isDeleted,
@Default(true) bool isLoading, @Default(true) bool isLoading,
@Default(null) ViewPB? lastCreatedView, @Default(null) ViewPB? lastCreatedView,
}) = _ViewState; }) = _ViewState;