view method
Display your widget.
Implementation
@override
Widget view(BuildContext context) {
Map<int, NavigationTab> pages = orderedPages;
_layout = layout(context);
if (_layout?.kind == "journey") {
return _buildJourneyLayout(context, pages);
}
if (_layout?.kind == "bottomNav") {
Widget body = maintainState
? IndexedStack(
index: currentIndex,
children: [
for (var page in pages.entries)
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) =>
page.value.page ?? SizedBox.shrink(),
settings: settings,
),
),
],
)
: Navigator(
key: getNavigationKey(pages.entries.elementAt(getCurrentIndex)),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) =>
(pages.entries.elementAt(getCurrentIndex).value.page ??
SizedBox.shrink()),
settings: settings,
),
);
// Build the navigation bar items
List<BottomNavigationBarItem> navItems = [
for (MapEntry<int, NavigationTab> page in pages.entries)
_buildBottomNavigationBarItem(page),
];
// Check for custom builder first
if (_layout?.navBarBuilder != null) {
final data = NavBarData(
items: navItems,
currentIndex: getCurrentIndex,
onTap: onTap,
);
Widget customNavBar = _layout!.navBarBuilder!(context, data);
try {
return bottomNavBuilder(context, body, customNavBar);
} on UnimplementedError catch (_) {
return Scaffold(body: body, bottomNavigationBar: customNavBar);
}
}
// Build standard nav bar
Widget bottomNavigationBar = BottomNavigationBar(
currentIndex: getCurrentIndex,
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: navItems,
);
// Apply style if provided
if (_layout?.style != null) {
bottomNavigationBar = _layout!.style!.build(
context,
bottomNavigationBar,
);
}
try {
return bottomNavBuilder(context, body, bottomNavigationBar);
} on UnimplementedError catch (_) {
return Scaffold(body: body, bottomNavigationBar: bottomNavigationBar);
}
}
if (_layout?.kind == "topNav") {
return DefaultTabController(
length: pages.length,
initialIndex: getCurrentIndex,
animationDuration: _layout?.animationDuration,
child: Scaffold(
appBar: AppBar(
backgroundColor: _layout?.backgroundColor,
title: pages[getCurrentIndex]?.title == null
? null
: Text(pages[getCurrentIndex]?.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)
_buildTab(page.value, page.key),
],
onTap: onTap,
),
),
body: maintainState
? IndexedStack(
index: getCurrentIndex,
children: [
for (var page in pages.entries)
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) =>
(page.value.page ?? SizedBox.shrink()),
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 ?? SizedBox.shrink()),
settings: settings,
),
),
],
),
),
);
}
throw Exception("Invalid layout type");
}