Skip to content

Instantly share code, notes, and snippets.

@berkanaslan
Created May 28, 2021 06:56
Show Gist options
  • Save berkanaslan/0d6de69ed17d09f20f76544b3af40c2f to your computer and use it in GitHub Desktop.
Save berkanaslan/0d6de69ed17d09f20f76544b3af40c2f to your computer and use it in GitHub Desktop.
class NavigationProvider extends ChangeNotifier {
/// [NavigationProvider] edinmek için shortcode
static NavigationProvider of(BuildContext context) =>
Provider.of<NavigationProvider>(context, listen: false);
// Açılış sayfası
int _currentScreenIndex = FIRST_SCREEN;
int get currentTabIndex => _currentScreenIndex;
Route<dynamic> onGenerateRoute(RouteSettings settings) {
print('Oluşturulan rota: ${settings.name}');
switch (settings.name) {
case PushedScreen.route:
return MaterialPageRoute(builder: (_) => PushedScreen());
case SimpleScreen.route:
return MaterialPageRoute(builder: (_) => SimpleScreen());
default:
return MaterialPageRoute(builder: (_) => Root());
}
}
final Map<int, Screen> _screens = {
FIRST_SCREEN: Screen(
title: 'First',
icon: Icons.home,
child: FirstScreen(),
initialRoute: FirstScreen.route,
navigatorState: GlobalKey<NavigatorState>(),
onGenerateRoute: (settings) {
print('Oluşturulan rota: ${settings.name}');
switch (settings.name) {
case PushedScreen.route:
return MaterialPageRoute(builder: (_) => PushedScreen());
default:
return MaterialPageRoute(builder: (_) => FirstScreen());
}
},
scrollController: ScrollController(),
),
SECOND_SCREEN: Screen(
title: 'Second',
icon: Icons.search,
child: SecondScreen(),
initialRoute: SecondScreen.route,
navigatorState: GlobalKey<NavigatorState>(),
onGenerateRoute: (settings) {
print('Oluşturulan route: ${settings.name}');
switch (settings.name) {
default:
return MaterialPageRoute(builder: (_) => SecondScreen());
}
},
scrollController: ScrollController(),
),
THIRD_SCREEN: Screen(
title: 'Third',
icon: Icons.favorite,
child: ThirdScreen(),
initialRoute: ThirdScreen.route,
navigatorState: GlobalKey<NavigatorState>(),
onGenerateRoute: (settings) {
print('Oluşturulan route: ${settings.name}');
switch (settings.name) {
default:
return MaterialPageRoute(builder: (_) => ThirdScreen());
}
},
scrollController: ScrollController(),
),
FOURTH_SCREEN: Screen(
title: 'Fourth',
icon: Icons.message,
child: FourthScreen(),
initialRoute: FourthScreen.route,
navigatorState: GlobalKey<NavigatorState>(),
onGenerateRoute: (settings) {
print('Oluşturulan route: ${settings.name}');
switch (settings.name) {
case SimpleScreen.route:
return MaterialPageRoute(builder: (_) => SimpleScreen());
default:
return MaterialPageRoute(builder: (_) => FourthScreen());
}
},
scrollController: ScrollController(),
),
};
List<Screen> get screens => _screens.values.toList();
Screen get currentScreen => _screens[_currentScreenIndex];
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment