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) {
|
2023-03-21 17:44:52 +00:00
|
|
|
final BuildContext? context = navigatorKey.currentContext;
|
|
|
|
|
|
|
|
if (context == null) {
|
|
|
|
showSnackBar(
|
2023-03-22 12:13:47 +00:00
|
|
|
'Could not show dialog. This should not happen, please report this.',
|
2023-03-22 11:38:18 +00:00
|
|
|
);
|
2023-03-21 17:44:52 +00:00
|
|
|
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(
|
2023-03-27 17:02:44 +00:00
|
|
|
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
|
|
|
}
|