diff --git a/lib/logic/get_it/navigation.dart b/lib/logic/get_it/navigation.dart index 15adc982..aef86d63 100644 --- a/lib/logic/get_it/navigation.dart +++ b/lib/logic/get_it/navigation.dart @@ -7,10 +7,14 @@ class NavigationService { GlobalKey(); final GlobalKey navigatorKey = GlobalKey(); - NavigatorState? get navigator => navigatorKey.currentState; - void showPopUpDialog(final AlertDialog dialog) { - final BuildContext context = navigatorKey.currentState!.overlay!.context; + final BuildContext? context = navigatorKey.currentContext; + + if (context == null) { + showSnackBar( + 'Could not show dialog. This should not happen, please report this.'); + return; + } showDialog( context: context, diff --git a/lib/main.dart b/lib/main.dart index 702d8280..b6e1dc31 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -63,45 +63,42 @@ class SelfprivacyApp extends StatelessWidget { final ThemeData lightThemeData; final ThemeData darkThemeData; - final _appRouter = RootRouter(); + final _appRouter = RootRouter(getIt.get().navigatorKey); @override Widget build(final BuildContext context) => Localization( - child: AnnotatedRegion( - value: SystemUiOverlayStyle.light, // Manually changing appbar color - child: BlocAndProviderConfig( - child: BlocBuilder( - builder: ( - final BuildContext context, - final AppSettingsState appSettings, - ) => - MaterialApp.router( - routeInformationParser: _appRouter.defaultRouteParser(), - routerDelegate: _appRouter.delegate(), - scaffoldMessengerKey: - getIt.get().scaffoldMessengerKey, - localizationsDelegates: context.localizationDelegates, - supportedLocales: context.supportedLocales, - locale: context.locale, - debugShowCheckedModeBanner: false, - title: 'SelfPrivacy', - theme: lightThemeData, - darkTheme: darkThemeData, - themeMode: appSettings.isAutoDarkModeOn - ? ThemeMode.system - : appSettings.isDarkModeOn - ? ThemeMode.dark - : ThemeMode.light, - builder: (final BuildContext context, final Widget? widget) { - Widget error = const Text('...rendering error...'); - if (widget is Scaffold || widget is Navigator) { - error = Scaffold(body: Center(child: error)); - } - ErrorWidget.builder = - (final FlutterErrorDetails errorDetails) => error; - return widget!; - }, - ), + child: BlocAndProviderConfig( + child: BlocBuilder( + builder: ( + final BuildContext context, + final AppSettingsState appSettings, + ) => + MaterialApp.router( + routeInformationParser: _appRouter.defaultRouteParser(), + routerDelegate: _appRouter.delegate(), + scaffoldMessengerKey: + getIt.get().scaffoldMessengerKey, + localizationsDelegates: context.localizationDelegates, + supportedLocales: context.supportedLocales, + locale: context.locale, + debugShowCheckedModeBanner: false, + title: 'SelfPrivacy', + theme: lightThemeData, + darkTheme: darkThemeData, + themeMode: appSettings.isAutoDarkModeOn + ? ThemeMode.system + : appSettings.isDarkModeOn + ? ThemeMode.dark + : ThemeMode.light, + builder: (final BuildContext context, final Widget? widget) { + Widget error = const Text('...rendering error...'); + if (widget is Scaffold || widget is Navigator) { + error = Scaffold(body: Center(child: error)); + } + ErrorWidget.builder = + (final FlutterErrorDetails errorDetails) => error; + return widget!; + }, ), ), ), diff --git a/lib/ui/pages/users/user_details.dart b/lib/ui/pages/users/user_details.dart index e7bb1995..63a7b171 100644 --- a/lib/ui/pages/users/user_details.dart +++ b/lib/ui/pages/users/user_details.dart @@ -231,9 +231,7 @@ class _SshKeysCard extends StatelessWidget { publicKey: key, ), ); - Navigator.of(context) - ..pop() - ..pop(); + context.popRoute(); }, ), ], diff --git a/lib/ui/router/router.dart b/lib/ui/router/router.dart index 13141fd5..c0afd0d6 100644 --- a/lib/ui/router/router.dart +++ b/lib/ui/router/router.dart @@ -99,7 +99,7 @@ Widget fadeThroughTransition( ], ) class RootRouter extends _$RootRouter { - RootRouter(); + RootRouter(GlobalKey super.navigatorKey); } // Function to map route names to route titles