Skip to content

Commit c497e86

Browse files
committed
fix: Navigation stack crashed while there is a modal
1 parent fc5b81b commit c497e86

File tree

5 files changed

+20
-53
lines changed

5 files changed

+20
-53
lines changed

lib/screens/search/utils/backspace_action.dart

-28
This file was deleted.

lib/utils/router/modal_route_entry.dart

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import 'package:rune/utils/router/base_route_entry.dart';
22

33
class ModalRouteEntry extends BaseRouteEntry {
44
final (bool, dynamic) Function()? canPop;
5+
final void Function() pop;
56

67
ModalRouteEntry({
78
required super.name,
89
super.arguments,
910
this.canPop,
11+
required this.pop,
1012
});
1113
}

lib/utils/router/modal_route_wrapper.dart

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class _ModalRouteWrapperState extends State<ModalRouteWrapper> {
3131
name: widget.name,
3232
arguments: widget.arguments,
3333
canPop: widget.canPop,
34+
pop: () {
35+
_handleClose(null);
36+
},
3437
),
3538
);
3639
}

lib/utils/router/navigation.dart

+15-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '../../widgets/router/rune_with_navigation_bar_and_playback_controllor.da
55
import '../../providers/router_path.dart';
66

77
import 'history.dart';
8+
import 'modal_route_entry.dart';
89
import 'route_entry.dart';
910
import 'modal_route_wrapper.dart';
1011
import 'router_transition_parameter.dart';
@@ -28,35 +29,32 @@ bool $canPop() {
2829
bool $pop() {
2930
final navigation = $state();
3031
if ($canPop()) {
31-
final (canPop, result) = $history.pop();
32+
final current = $history.current;
33+
34+
final canPop = $canPop();
3235
if (!canPop) return false;
3336

34-
final current = $history.current;
3537
if (current != null) {
38+
if (current is ModalRouteEntry) {
39+
current.pop();
40+
$history.pop();
41+
return true;
42+
}
43+
3644
if (current is RouteEntry) {
45+
final (success, result) = $history.pop();
3746
final settings = current.toSettings();
3847
$router.update(settings.name, settings.arguments);
48+
navigation.pop(result);
49+
return true;
3950
}
40-
navigation.pop(result);
51+
52+
return false;
4153
}
42-
return true;
4354
}
4455
return false;
4556
}
4657

47-
Future<bool> $popModal() async {
48-
if (!$history.isCurrentModal) {
49-
return false;
50-
}
51-
52-
final (canPop, result) = $history.pop();
53-
if (canPop) {
54-
final navigation = $state();
55-
navigation.pop(result);
56-
}
57-
return true;
58-
}
59-
6058
Future<T?> $showModal<T extends Object?>(
6159
BuildContext context,
6260
Widget Function(BuildContext context, void Function(T? result) close)

lib/utils/router/navigation_history.dart

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ class NavigationHistory {
3434
(bool, dynamic) pop() {
3535
if (history.isEmpty) return (false, null);
3636

37-
final last = history.last;
38-
if (last is ModalRouteEntry && last.canPop != null) {
39-
final result = last.canPop!();
40-
if (!result.$1) return (false, null);
41-
history.removeLast();
42-
return result;
43-
}
44-
4537
history.removeLast();
4638
return (true, null);
4739
}

0 commit comments

Comments
 (0)