import 'package:diplomaticquarterapp/locator.dart';
import 'package:flutter/material.dart';

MaterialPageRoute _pageRoute(Widget page) => MaterialPageRoute(builder: (BuildContext context) => page);

class NavigationService {
  final GlobalKey<NavigatorState> navigatorKey =
      new GlobalKey<NavigatorState>();


  static Future<dynamic> navigateTo(String routeName) {
    final key = locator<NavigationService>().navigatorKey;
    return key.currentState.pushNamed(routeName);
  }

  static Future<dynamic> navigateToPage(Widget page) {
    final key = locator<NavigationService>().navigatorKey;
    final pageRoute = MaterialPageRoute(builder: (context) => page);
    return Navigator.push(key.currentContext, pageRoute);
  }
}

class Navigate{
  static to({@required Widget page}){
    final context = locator<NavigationService>().navigatorKey.currentContext;
    Navigator.of(context).push(_pageRoute(page));
  }
}

BuildContext get  currentContext => locator<NavigationService>().navigatorKey.currentContext;
