view method
Display your widget.
Implementation
@override
Widget view(BuildContext context) {
Map<int, NavigationTab> pages = orderedPages;
if (layout?.kind == "bottomNav") {
return Scaffold(
body: maintainState
? IndexedStack(index: currentIndex, children: [
for (var page in pages.entries)
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => page.value.page,
settings: settings,
),
)
])
: Navigator(
key: getNavigationKey(pages.entries.elementAt(currentIndex)),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) =>
(pages.entries.elementAt(currentIndex).value.page),
settings: settings,
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
onTap: onTap,
selectedLabelStyle: layout?.selectedLabelStyle ??
TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
),
unselectedLabelStyle: layout?.unselectedLabelStyle ??
TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
),
showSelectedLabels: layout?.showSelectedLabels ?? true,
showUnselectedLabels: layout?.showUnselectedLabels ?? true,
selectedItemColor: layout?.selectedItemColor ?? Colors.black,
unselectedItemColor: layout?.unselectedItemColor ?? Colors.black,
selectedFontSize: layout?.selectedFontSize ?? 14.0,
unselectedFontSize: layout?.unselectedFontSize ?? 12.0,
iconSize: layout?.iconSize ?? 24.0,
elevation: layout?.elevation ?? 8.0,
backgroundColor: layout?.backgroundColor,
type: layout?.type ?? BottomNavigationBarType.fixed,
items: [
for (MapEntry<int, NavigationTab> page in pages.entries)
_getBottomNavigationBarItem(page),
],
),
);
}
if (layout?.kind == "topNav") {
return DefaultTabController(
length: pages.length,
initialIndex: currentIndex,
animationDuration: layout?.animationDuration,
child: Scaffold(
appBar: AppBar(
backgroundColor: layout?.backgroundColor,
title: pages[currentIndex]?.title == null
? null
: Text(pages[currentIndex]?.title ?? ""),
toolbarHeight: (layout?.hideAppBarTitle ?? true) ? 0 : null,
bottom: TabBar(
isScrollable: layout?.isScrollable ?? false,
labelColor: layout?.labelColor,
labelStyle: layout?.labelStyle,
labelPadding: layout?.labelPadding,
unselectedLabelColor: layout?.unselectedLabelColor,
unselectedLabelStyle: layout?.unselectedLabelStyle,
indicatorColor: layout?.indicatorColor,
automaticIndicatorColorAdjustment:
layout?.automaticIndicatorColorAdjustment ?? true,
indicatorWeight: layout?.indicatorWeight ?? 2.0,
indicatorPadding: layout?.indicatorPadding ?? EdgeInsets.zero,
indicator: layout?.indicator,
indicatorSize: layout?.indicatorSize,
dividerColor: layout?.dividerColor,
dividerHeight: layout?.dividerHeight,
dragStartBehavior:
layout?.dragStartBehavior ?? DragStartBehavior.start,
overlayColor: layout?.overlayColorState,
mouseCursor: layout?.mouseCursor,
enableFeedback: layout?.enableFeedback,
physics: layout?.physics,
splashFactory: layout?.splashFactory,
splashBorderRadius: layout?.splashBorderRadius,
tabAlignment: layout?.tabAlignment,
textScaler: layout?.textScaler,
tabs: [
for (MapEntry page in pages.entries)
Tab(
text: layout?.showSelectedLabels == false
? null
: page.value.title,
icon: page.value.kind == "badge"
? BadgeTab.fromNavigationTab(page.value,
index: page.key,
icon: currentIndex == page.key
? page.value.activeIcon ?? Icon(Icons.home)
: page.value.icon ?? Icon(Icons.home),
stateName:
"${stateName}_navigation_tab_${page.key}")
: currentIndex == page.key
? page.value.activeIcon ?? Icon(Icons.home)
: page.value.icon ?? Icon(Icons.home),
)
],
onTap: onTap,
),
),
body: maintainState
? IndexedStack(index: currentIndex, children: [
for (var page in pages.entries)
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => (page.value.page),
settings: settings,
),
)
])
: TabBarView(
physics: layout?.physics,
children: [
for (var page in pages.entries)
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => (page.value.page),
settings: settings,
),
)
],
),
),
);
}
throw Exception("Invalid layout type");
}