Layout changes, fix bugs in new entry page

This commit is contained in:
2025-12-22 17:23:21 +00:00
parent 63b545c7a3
commit 45d543498f
20 changed files with 779 additions and 192 deletions

View File

@@ -31,6 +31,21 @@ const List<String> _contentPages = [
const int _addTabIndex = 5;
class _NavItem {
final String label;
final IconData icon;
const _NavItem(this.label, this.icon);
}
const List<_NavItem> _navItems = [
_NavItem("Home", Icons.home),
_NavItem("Calculator", Icons.route),
_NavItem("Entries", Icons.list),
_NavItem("Traction", Icons.train),
_NavItem("Trips", Icons.book),
_NavItem("Add", Icons.add),
];
int tabIndexForPath(String path) {
final newIndex = _contentPages.indexWhere((routePath) {
if (path == routePath) return true;
@@ -218,6 +233,9 @@ class _MyHomePageState extends State<MyHomePage> {
if (data.traction.isEmpty) {
data.fetchHadTraction();
}
if (data.latestLocoChanges.isEmpty) {
data.fetchLatestLocoChanges();
}
if (data.onThisDay.isEmpty) {
data.fetchOnThisDay();
}
@@ -273,41 +291,82 @@ class _MyHomePageState extends State<MyHomePage> {
SystemNavigator.pop();
},
child: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text.rich(
TextSpan(
children: const [
TextSpan(text: "Mile"),
TextSpan(text: "O", style: TextStyle(color: Colors.red)),
TextSpan(text: "graph"),
],
style: const TextStyle(
decoration: TextDecoration.none,
color: Colors.white,
fontFamily: "Tomatoes",
child: LayoutBuilder(
builder: (context, constraints) {
final isWide = constraints.maxWidth >= 900;
final railExtended = constraints.maxWidth >= 1400;
final navRailDestinations = _navItems
.map(
(item) => NavigationRailDestination(
icon: Icon(item.icon),
label: Text(item.label),
),
)
.toList();
final navBarDestinations = _navItems
.map(
(item) => NavigationDestination(
icon: Icon(item.icon),
label: item.label,
),
)
.toList();
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text.rich(
TextSpan(
children: const [
TextSpan(text: "Mile"),
TextSpan(text: "O", style: TextStyle(color: Colors.red)),
TextSpan(text: "graph"),
],
style: const TextStyle(
decoration: TextDecoration.none,
color: Colors.white,
fontFamily: "Tomatoes",
),
),
),
actions: [
const IconButton(
onPressed: null,
icon: Icon(Icons.account_circle),
),
IconButton(onPressed: auth.logout, icon: const Icon(Icons.logout)),
],
),
),
actions: [
const IconButton(onPressed: null, icon: Icon(Icons.account_circle)),
IconButton(onPressed: auth.logout, icon: const Icon(Icons.logout)),
],
),
bottomNavigationBar: NavigationBar(
selectedIndex: pageIndex,
onDestinationSelected: (int index) => _onItemTapped(index, pageIndex),
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: "Home"),
NavigationDestination(icon: Icon(Icons.route), label: "Calculator"),
NavigationDestination(icon: Icon(Icons.list), label: "Entries"),
NavigationDestination(icon: Icon(Icons.train), label: "Traction"),
NavigationDestination(icon: Icon(Icons.book), label: "Trips"),
NavigationDestination(icon: Icon(Icons.add), label: "Add"),
],
),
body: currentPage,
bottomNavigationBar: isWide
? null
: NavigationBar(
selectedIndex: pageIndex,
onDestinationSelected: (int index) =>
_onItemTapped(index, pageIndex),
destinations: navBarDestinations,
),
body: isWide
? Row(
children: [
SafeArea(
child: NavigationRail(
selectedIndex: pageIndex,
extended: railExtended,
labelType: railExtended
? NavigationRailLabelType.none
: NavigationRailLabelType.selected,
onDestinationSelected: (int index) =>
_onItemTapped(index, pageIndex),
destinations: navRailDestinations,
),
),
const VerticalDivider(width: 1),
Expanded(child: currentPage),
],
)
: currentPage,
);
},
),
);
}