You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
825 B
Dart
26 lines
825 B
Dart
|
3 years ago
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:get_it/get_it.dart';
|
||
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
||
|
|
import 'package:mohem_flutter_app/config/routes.dart';
|
||
|
|
|
||
|
|
final locator = GetIt.instance;
|
||
|
|
|
||
|
|
class NavigationService {
|
||
|
|
final GlobalKey<NavigatorState> navigatorKey = AppRoutes.navigatorKey;
|
||
|
|
|
||
|
|
static Future<dynamic> navigateTo(String routeName) {
|
||
|
|
var key = locator<NavigationService>().navigatorKey;
|
||
|
|
return key.currentState!.pushNamed(routeName);
|
||
|
|
}
|
||
|
|
|
||
|
|
static Future<dynamic> navigateToPage(Widget page) {
|
||
|
|
var key = locator<NavigationService>().navigatorKey;
|
||
|
|
var pageRoute = MaterialPageRoute(builder: (context) => page);
|
||
|
|
return Navigator.push(key.currentContext!, pageRoute);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void setupLocator() {
|
||
|
|
locator.registerLazySingleton( ()=> NavigationService());
|
||
|
|
}
|