selfprivacy.org.app/lib/logic/get_it/navigation.dart

33 lines
882 B
Dart
Raw Normal View History

2021-02-15 18:58:29 +00:00
import 'package:flutter/material.dart';
class NavigationService {
2021-08-29 09:50:24 +00:00
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>();
2021-02-15 18:58:29 +00:00
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
2021-08-29 09:50:24 +00:00
2022-06-05 19:36:32 +00:00
void showPopUpDialog(final AlertDialog dialog) {
final BuildContext? context = navigatorKey.currentContext;
if (context == null) {
showSnackBar(
'Could not show dialog. This should not happen, please report this.',
);
return;
}
2021-02-15 18:58:29 +00:00
showDialog(
context: context,
2022-06-05 19:36:32 +00:00
builder: (final _) => dialog,
2021-02-15 18:58:29 +00:00
);
}
2021-08-29 09:50:24 +00:00
2022-06-05 19:36:32 +00:00
void showSnackBar(final String text) {
final ScaffoldMessengerState state = scaffoldMessengerKey.currentState!;
final SnackBar snack = SnackBar(
content: Text(text),
2021-09-15 14:37:22 +00:00
duration: const Duration(seconds: 2),
);
state.showSnackBar(snack);
2021-08-29 09:50:24 +00:00
}
2021-02-15 18:58:29 +00:00
}