fix(android): intercept back during cold startup and move exit toast down

This commit is contained in:
Levi committed 2026-09-12 20:40:07 +08:00
1 parent ee6b073bc1
commit bd03d3b31c
8 files changed
+195 -48

No files matched your search

+26 -15
View File
@@ -17,6 +17,7 @@ import '../../features/tasks/presentation/pages/task_details_page.dart';
import '../../features/tasks/presentation/pages/task_files_page.dart';
import 'shells/main_shell.dart';
import 'mobile_exit_guard.dart';
import 'runtime_page.dart';
class AppRouter {
static final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
@@ -35,24 +36,26 @@ class AppRouter {
final sectionRoutes = [
GoRoute(
path: isMobile ? 'extensions' : '/extensions',
builder: (context, state) => const ExtensionsPage(),
builder: _runtimePage((context, state) => const ExtensionsPage()),
routes: [
GoRoute(
path: ':id',
builder: (context, state) => ExtensionDetailsPage(
extensionId: state.pathParameters['id'] ?? '',
initialItem: state.extra is ExtensionListItem ? state.extra as ExtensionListItem : null,
builder: _runtimePage(
(context, state) => ExtensionDetailsPage(
extensionId: state.pathParameters['id'] ?? '',
initialItem: state.extra is ExtensionListItem ? state.extra as ExtensionListItem : null,
),
),
),
],
),
GoRoute(
path: isMobile ? 'settings' : '/settings',
builder: (context, state) => const SettingsPage(),
builder: _runtimePage((context, state) => const SettingsPage()),
routes: [
GoRoute(
path: ':section',
builder: (context, state) => SettingsPage(sectionKey: state.pathParameters['section']),
builder: _runtimePage((context, state) => SettingsPage(sectionKey: state.pathParameters['section'])),
),
],
),
@@ -74,25 +77,29 @@ class AppRouter {
routes: [
GoRoute(path: '/login', parentNavigatorKey: rootNavigatorKey, builder: (context, state) => const LoginPage()),
ShellRoute(
builder: (context, state, child) => MainShell(child: child),
builder: (context, state, child) => MobileExitGuard(child: MainShell(child: child)),
routes: [
GoRoute(
path: '/',
builder: (context, state) => const MobileExitGuard(child: HomePage()),
builder: _runtimePage((context, state) => const HomePage()),
routes: [
GoRoute(path: 'create', builder: (context, state) => const CreateTaskWindowPage()),
GoRoute(path: 'create', builder: _runtimePage((context, state) => const CreateTaskWindowPage())),
GoRoute(
path: 'tasks/:id',
builder: (context, state) => TaskDetailsPage(
taskId: state.pathParameters['id'] ?? '',
initialTask: state.extra is TaskRecord ? state.extra as TaskRecord : null,
builder: _runtimePage(
(context, state) => TaskDetailsPage(
taskId: state.pathParameters['id'] ?? '',
initialTask: state.extra is TaskRecord ? state.extra as TaskRecord : null,
),
),
routes: [
GoRoute(
path: 'files',
builder: (context, state) => TaskFilesPage(
taskId: state.pathParameters['id'] ?? '',
initialTask: state.extra is TaskRecord ? state.extra as TaskRecord : null,
builder: _runtimePage(
(context, state) => TaskFilesPage(
taskId: state.pathParameters['id'] ?? '',
initialTask: state.extra is TaskRecord ? state.extra as TaskRecord : null,
),
),
),
],
@@ -107,6 +114,10 @@ class AppRouter {
);
}
static GoRouterWidgetBuilder _runtimePage(GoRouterWidgetBuilder builder) {
return (context, state) => RuntimePage(builder: (context) => builder(context, state));
}
static String _safeReturnLocation(String? location) {
if (location == null || location.isEmpty) return '/';
final uri = Uri.tryParse(location);