구조
Routers.dart
import 'package:flutter/material.dart';
import 'package:luxury_items_sharing/ui/screens/home/home.dart';
import 'core/fade_page_route.dart';
enum Routes {home}
class _Paths {
static const String home = '/home';
static const Map<Routes, String> _pathMap = {
Routes.home : _Paths.home
};
static String of(Routes route) => _pathMap[route] ?? home;
}
class AppNavigator {
static GlobalKey<NavigatorState> navigatorKey = GlobalKey(); //하위 위젯을 컨트롤 하기 위해 navigatorKey 를 사용
static Route onGenerateRoute(RouteSettings settings){
switch(settings.name){
case _Paths.home:
return FadeRoute(page: HomeScreen());
default:
return FadeRoute(page: HomeScreen());
}
}
static Future? push<T>(Routes route, [T? arguments]) =>
state?.pushNamed(_Paths.of(route), arguments: arguments);
static Future? replaceWith<T>(Routes route, [T? arguments]) =>
state?.pushReplacementNamed(_Paths.of(route), arguments: arguments);
static void pop() => state?.pop();
static NavigatorState? get state => navigatorKey.currentState;
}
home.dart