view method

  1. @override
Widget view(
  1. BuildContext context
)
override

Display your widget.

Implementation

@override
Widget view(BuildContext context) {
  Map<int, NavigationTab> pages = orderedPages;

  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,
            ),
          );

    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: [
        for (MapEntry<int, NavigationTab> page in pages.entries)
          _buildBottomNavigationBarItem(page),
      ],
    );
    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");
}