Skip to content

Instantly share code, notes, and snippets.

@berkanaslan
Created May 28, 2021 06:58
Show Gist options
  • Save berkanaslan/4f5cc406c4128893af711207aa9a25f5 to your computer and use it in GitHub Desktop.
Save berkanaslan/4f5cc406c4128893af711207aa9a25f5 to your computer and use it in GitHub Desktop.
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