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

32 lines
973 B
Dart
Raw Normal View History

2021-02-15 18:58:29 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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
2021-03-15 15:39:44 +00:00
NavigatorState? get navigator => navigatorKey.currentState;
2021-02-15 18:58:29 +00:00
void showPopUpDialog(AlertDialog dialog) {
2021-03-15 15:39:44 +00:00
final context = navigatorKey.currentState!.overlay!.context;
2021-02-15 18:58:29 +00:00
showDialog(
context: context,
builder: (_) => dialog,
);
}
2021-08-29 09:50:24 +00:00
2021-09-15 14:37:22 +00:00
void showSnackBar(String text) {
2021-08-29 09:50:24 +00:00
final state = scaffoldMessengerKey.currentState!;
2021-09-15 14:37:22 +00:00
final snack = SnackBar(
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
}