Created
May 28, 2021 06:58
-
-
Save berkanaslan/4f5cc406c4128893af711207aa9a25f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Root extends StatelessWidget { | |
static const route = '/'; | |
@override | |
Widget build(BuildContext context) { | |
return Consumer<NavigationProvider>( | |
builder: (context, provider, child) { | |
// Tanımladığımız screen'lardan BottomNavigationBar oluşturma | |
final bottomNavigationBarItems = provider.screens | |
.map( | |
(screen) => BottomNavigationBarItem( | |
icon: Icon(screen.icon), | |
label: screen.title, | |
), | |
) | |
.toList(); | |
// Her ekran için [Navigator] örneğini başlatma | |
final screens = provider.screens | |
.map( | |
(screen) => Navigator( | |
key: screen.navigatorState, | |
onGenerateRoute: screen.onGenerateRoute, | |
), | |
) | |
.toList(); | |
return WillPopScope( | |
onWillPop: () async => provider.onWillPop(context), | |
child: Scaffold( | |
body: IndexedStack( | |
children: screens, | |
index: provider.currentTabIndex, | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
type: BottomNavigationBarType.fixed, | |
items: bottomNavigationBarItems, | |
currentIndex: provider.currentTabIndex, | |
onTap: provider.setTab, | |
), | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment