mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 22:03:41 +00:00
fix(ui): preserve mobile home route and confirm Android exit (#1507)
This commit is contained in:
10 files changed
+484
-96
No files matched your search
@@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
import '../../../api/model/create_task.dart';
|
||||
import '../../application/app_deep_link_controller.dart';
|
||||
@@ -16,10 +15,7 @@ import '../../../features/tasks/application/pending_create_task.dart';
|
||||
import '../../../features/tasks/application/pending_update_task.dart';
|
||||
import '../../../features/tasks/application/tasks_controller.dart';
|
||||
import '../../../features/tasks/presentation/widgets/pending_update_dialog.dart';
|
||||
import '../../../l10n/l10n.dart';
|
||||
import '../../../core/window/app_window_launcher.dart';
|
||||
import '../../../core/utils/breakpoints.dart';
|
||||
import '../../../shared/navigation/app_exit_confirmation_controller.dart';
|
||||
import '../../../shared/widgets/app_toast.dart';
|
||||
|
||||
class MainShell extends ConsumerStatefulWidget {
|
||||
@@ -34,7 +30,6 @@ class MainShell extends ConsumerStatefulWidget {
|
||||
class _MainShellState extends ConsumerState<MainShell> {
|
||||
String? _shownUpdateVersion;
|
||||
bool _handlingPendingUpdateRequest = false;
|
||||
final _exitConfirmationController = AppExitConfirmationController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -65,40 +60,13 @@ class _MainShellState extends ConsumerState<MainShell> {
|
||||
}
|
||||
});
|
||||
final runtime = ref.watch(appRuntimeControllerProvider);
|
||||
final content = runtime.when(
|
||||
loading: () => const shad.Scaffold(child: Center(child: shad.CircularProgressIndicator())),
|
||||
error: (error, _) => shad.Scaffold(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: Text(context.l10n.runtimeInitializationFailed(error.toString()), textAlign: TextAlign.center),
|
||||
),
|
||||
),
|
||||
),
|
||||
data: (_) {
|
||||
ref.watch(appPlatformControllerProvider);
|
||||
ref.watch(appDeepLinkControllerProvider);
|
||||
ref.watch(appNotificationControllerProvider);
|
||||
return widget.child;
|
||||
},
|
||||
);
|
||||
return _buildMobileBackGuard(context, content);
|
||||
}
|
||||
|
||||
Widget _buildMobileBackGuard(BuildContext context, Widget child) {
|
||||
final isAndroidMobile =
|
||||
!kIsWeb &&
|
||||
defaultTargetPlatform == TargetPlatform.android &&
|
||||
MediaQuery.sizeOf(context).width < Breakpoints.mobile;
|
||||
if (!isAndroidMobile || context.canPop()) return child;
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) unawaited(_exitConfirmationController.handleBack(context));
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
if (runtime.hasValue) {
|
||||
ref.watch(appPlatformControllerProvider);
|
||||
ref.watch(appDeepLinkControllerProvider);
|
||||
ref.watch(appNotificationControllerProvider);
|
||||
}
|
||||
// Keep the nested Navigator mounted even while the runtime is starting.
|
||||
return widget.child;
|
||||
}
|
||||
|
||||
void _schedulePendingUpdateRequest(PendingUpdateRequest request) {
|
||||
|
||||
Reference in new issue
Block a user