Skip to content

Commit

Permalink
refactor(app): add tab routes definition
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 21, 2023
1 parent 1b2989e commit c93eebe
Showing 1 changed file with 47 additions and 26 deletions.
73 changes: 47 additions & 26 deletions app/lib/common/pages/main/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,51 @@ import 'package:flutter/material.dart';
import '../../l10n.dart';
import '../../routing/router.dart';

class TabRouteDefinition {
TabRouteDefinition({
required this.pageRouteInfo,
required this.label,
required this.icon,
});
PageRouteInfo<void> pageRouteInfo;
String label;
Icon icon;
}

List<TabRouteDefinition> getTabRoutesDefinition(BuildContext context) {
return [
TabRouteDefinition(
pageRouteInfo: ReportRouter(),
label: context.l10n.nav_report,
icon: Icon(Icons.summarize_rounded),
),
TabRouteDefinition(
pageRouteInfo: SearchRouter(),
label: context.l10n.nav_drugs,
icon: Icon(Icons.medication_rounded),
),
TabRouteDefinition(
pageRouteInfo: FaqRouter(),
label: context.l10n.nav_faq,
icon: Icon(Icons.lightbulb_rounded),
),
TabRouteDefinition(
pageRouteInfo: SettingsRouter(),
label: context.l10n.nav_more,
icon: Icon(Icons.more_horiz_rounded),
),
];
}

class MainPage extends StatelessWidget {
const MainPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return AutoTabsScaffold(
routes: const [
// The order maps to BottomNavigationBar
ReportRouter(),
SearchRouter(),
FaqRouter(),
SettingsRouter(),
],
routes: getTabRoutesDefinition(context).map(
(routeDefinition) => routeDefinition.pageRouteInfo
).toList(),
bottomNavigationBuilder: (_, tabsRouter) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
Expand All @@ -35,24 +67,13 @@ class MainPage extends StatelessWidget {
}

List<BottomNavigationBarItem> _bottomNavigationBarItems(
BuildContext context) {
return <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.summarize_rounded),
label: context.l10n.nav_report,
),
BottomNavigationBarItem(
icon: Icon(Icons.medication_rounded),
label: context.l10n.nav_drugs,
),
BottomNavigationBarItem(
icon: Icon(Icons.lightbulb_rounded),
label: context.l10n.nav_faq,
),
BottomNavigationBarItem(
icon: Icon(Icons.more_horiz_rounded),
label: context.l10n.nav_more,
),
];
BuildContext context
) {
return getTabRoutesDefinition(context).map(
(routeDefinition) => BottomNavigationBarItem(
icon: routeDefinition.icon,
label: routeDefinition.label,
)
).toList();
}
}

0 comments on commit c93eebe

Please sign in to comment.