12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import 'package:flutter/services.dart';
- class MyRouterHistoryManager {
-
- static const onlyVerticalOrientationRouterName = [
- "AUTH_LOGIN",
- "SPLASH",
- ];
- static final MyRouterHistoryManager _instance = MyRouterHistoryManager._internal();
- factory MyRouterHistoryManager() {
- return _instance;
- }
- MyRouterHistoryManager._internal();
- final List<String?> _routeNames = [];
-
- void putRouterByName(String? routeName) {
- if (routeName != null) {
- _routeNames.add(routeName);
- try2SetVerticalOrientation(routeName);
- }
- }
-
- void removeRouterByName(String? routeName) {
- if (routeName != null && _routeNames.contains(routeName)) {
- _routeNames.remove(routeName);
- try2RestoreOrientation(routeName);
- }
- }
-
- void try2SetVerticalOrientation(String routeName) {
- if (onlyVerticalOrientationRouterName.contains(routeName)) {
-
- SystemChrome.setPreferredOrientations([
- DeviceOrientation.portraitUp,
- ]);
- }
- }
-
- void try2RestoreOrientation(String routeName) {
- if (onlyVerticalOrientationRouterName.contains(routeName)) {
-
- SystemChrome.setPreferredOrientations([
- DeviceOrientation.portraitUp,
- DeviceOrientation.landscapeLeft,
- DeviceOrientation.landscapeRight,
- ]);
- }
- }
-
- List<String?> get routeNames => _routeNames;
-
- bool isRouteExist(String routeName) {
- return _routeNames.contains(routeName);
- }
-
- bool isTopRouteExist(String routeName) {
- if (_routeNames.isNotEmpty) {
- return _routeNames.last == routeName;
- } else {
- return false;
- }
- }
- }
|