mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 11:16:45 +00:00
fix(router): PopUpDialogs couldn't find the context.
This commit is contained in:
parent
ee9b8a4e31
commit
3366585d76
|
@ -7,10 +7,14 @@ class NavigationService {
|
||||||
GlobalKey<ScaffoldMessengerState>();
|
GlobalKey<ScaffoldMessengerState>();
|
||||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
NavigatorState? get navigator => navigatorKey.currentState;
|
|
||||||
|
|
||||||
void showPopUpDialog(final AlertDialog dialog) {
|
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(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
|
@ -63,45 +63,42 @@ class SelfprivacyApp extends StatelessWidget {
|
||||||
final ThemeData lightThemeData;
|
final ThemeData lightThemeData;
|
||||||
final ThemeData darkThemeData;
|
final ThemeData darkThemeData;
|
||||||
|
|
||||||
final _appRouter = RootRouter();
|
final _appRouter = RootRouter(getIt.get<NavigationService>().navigatorKey);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) => Localization(
|
Widget build(final BuildContext context) => Localization(
|
||||||
child: AnnotatedRegion<SystemUiOverlayStyle>(
|
child: BlocAndProviderConfig(
|
||||||
value: SystemUiOverlayStyle.light, // Manually changing appbar color
|
child: BlocBuilder<AppSettingsCubit, AppSettingsState>(
|
||||||
child: BlocAndProviderConfig(
|
builder: (
|
||||||
child: BlocBuilder<AppSettingsCubit, AppSettingsState>(
|
final BuildContext context,
|
||||||
builder: (
|
final AppSettingsState appSettings,
|
||||||
final BuildContext context,
|
) =>
|
||||||
final AppSettingsState appSettings,
|
MaterialApp.router(
|
||||||
) =>
|
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||||
MaterialApp.router(
|
routerDelegate: _appRouter.delegate(),
|
||||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
scaffoldMessengerKey:
|
||||||
routerDelegate: _appRouter.delegate(),
|
getIt.get<NavigationService>().scaffoldMessengerKey,
|
||||||
scaffoldMessengerKey:
|
localizationsDelegates: context.localizationDelegates,
|
||||||
getIt.get<NavigationService>().scaffoldMessengerKey,
|
supportedLocales: context.supportedLocales,
|
||||||
localizationsDelegates: context.localizationDelegates,
|
locale: context.locale,
|
||||||
supportedLocales: context.supportedLocales,
|
debugShowCheckedModeBanner: false,
|
||||||
locale: context.locale,
|
title: 'SelfPrivacy',
|
||||||
debugShowCheckedModeBanner: false,
|
theme: lightThemeData,
|
||||||
title: 'SelfPrivacy',
|
darkTheme: darkThemeData,
|
||||||
theme: lightThemeData,
|
themeMode: appSettings.isAutoDarkModeOn
|
||||||
darkTheme: darkThemeData,
|
? ThemeMode.system
|
||||||
themeMode: appSettings.isAutoDarkModeOn
|
: appSettings.isDarkModeOn
|
||||||
? ThemeMode.system
|
? ThemeMode.dark
|
||||||
: appSettings.isDarkModeOn
|
: ThemeMode.light,
|
||||||
? ThemeMode.dark
|
builder: (final BuildContext context, final Widget? widget) {
|
||||||
: ThemeMode.light,
|
Widget error = const Text('...rendering error...');
|
||||||
builder: (final BuildContext context, final Widget? widget) {
|
if (widget is Scaffold || widget is Navigator) {
|
||||||
Widget error = const Text('...rendering error...');
|
error = Scaffold(body: Center(child: error));
|
||||||
if (widget is Scaffold || widget is Navigator) {
|
}
|
||||||
error = Scaffold(body: Center(child: error));
|
ErrorWidget.builder =
|
||||||
}
|
(final FlutterErrorDetails errorDetails) => error;
|
||||||
ErrorWidget.builder =
|
return widget!;
|
||||||
(final FlutterErrorDetails errorDetails) => error;
|
},
|
||||||
return widget!;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -231,9 +231,7 @@ class _SshKeysCard extends StatelessWidget {
|
||||||
publicKey: key,
|
publicKey: key,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Navigator.of(context)
|
context.popRoute();
|
||||||
..pop()
|
|
||||||
..pop();
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -99,7 +99,7 @@ Widget fadeThroughTransition(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
class RootRouter extends _$RootRouter {
|
class RootRouter extends _$RootRouter {
|
||||||
RootRouter();
|
RootRouter(GlobalKey<NavigatorState> super.navigatorKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to map route names to route titles
|
// Function to map route names to route titles
|
||||||
|
|
Loading…
Reference in a new issue