fix(router): PopUpDialogs couldn't find the context.

pull/203/head
Inex Code 2023-03-21 20:44:52 +03:00 committed by Gitea
parent ee9b8a4e31
commit 3366585d76
4 changed files with 42 additions and 43 deletions

View File

@ -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,

View File

@ -63,12 +63,10 @@ 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>(
value: SystemUiOverlayStyle.light, // Manually changing appbar color
child: BlocAndProviderConfig( child: BlocAndProviderConfig(
child: BlocBuilder<AppSettingsCubit, AppSettingsState>( child: BlocBuilder<AppSettingsCubit, AppSettingsState>(
builder: ( builder: (
@ -104,6 +102,5 @@ class SelfprivacyApp extends StatelessWidget {
), ),
), ),
), ),
),
); );
} }

View File

@ -231,9 +231,7 @@ class _SshKeysCard extends StatelessWidget {
publicKey: key, publicKey: key,
), ),
); );
Navigator.of(context) context.popRoute();
..pop()
..pop();
}, },
), ),
], ],

View File

@ -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