2021-02-15 18:58:29 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-15 14:37:22 +00:00
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
|
|
|
import 'package:selfprivacy/config/text_themes.dart';
|
2021-02-15 18:58:29 +00:00
|
|
|
|
|
|
|
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 11:38:18 +00:00
|
|
|
'Could not show dialog. This should not happen, please report this.',
|
|
|
|
);
|
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(
|
2021-09-15 14:37:22 +00:00
|
|
|
backgroundColor: BrandColors.black.withOpacity(0.8),
|
|
|
|
content: Text(text, style: buttonTitleText),
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
);
|
|
|
|
state.showSnackBar(snack);
|
2021-08-29 09:50:24 +00:00
|
|
|
}
|
2021-02-15 18:58:29 +00:00
|
|
|
}
|