re add calculator page
This commit is contained in:
@@ -3,6 +3,8 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mileograph_flutter/components/pages/calculator.dart';
|
||||
import 'package:mileograph_flutter/components/pages/calculator_details.dart';
|
||||
import 'package:mileograph_flutter/components/login/login.dart';
|
||||
import 'package:mileograph_flutter/components/pages/dashboard.dart';
|
||||
import 'package:mileograph_flutter/components/pages/loco_legs.dart';
|
||||
@@ -19,10 +21,12 @@ import 'package:mileograph_flutter/services/data_service.dart';
|
||||
import 'package:mileograph_flutter/services/navigation_guard.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final GlobalKey<NavigatorState> _shellNavigatorKey = GlobalKey<NavigatorState>();
|
||||
final GlobalKey<NavigatorState> _shellNavigatorKey =
|
||||
GlobalKey<NavigatorState>();
|
||||
|
||||
const List<String> _contentPages = [
|
||||
"/dashboard",
|
||||
"/calculator",
|
||||
"/logbook",
|
||||
"/traction",
|
||||
"/add",
|
||||
@@ -31,13 +35,14 @@ const List<String> _contentPages = [
|
||||
|
||||
const List<String> _defaultTabDestinations = [
|
||||
"/dashboard",
|
||||
"/calculator",
|
||||
"/logbook/entries",
|
||||
"/traction",
|
||||
"/add",
|
||||
"/more",
|
||||
];
|
||||
|
||||
const int _addTabIndex = 3;
|
||||
const int _addTabIndex = 4;
|
||||
|
||||
class _NavItem {
|
||||
final String label;
|
||||
@@ -47,6 +52,7 @@ class _NavItem {
|
||||
|
||||
const List<_NavItem> _navItems = [
|
||||
_NavItem("Home", Icons.home),
|
||||
_NavItem("Calculator", Icons.route),
|
||||
_NavItem("Logbook", Icons.menu_book),
|
||||
_NavItem("Traction", Icons.train),
|
||||
_NavItem("Add", Icons.add),
|
||||
@@ -112,10 +118,7 @@ class _MyAppState extends State<MyApp> {
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
redirect: (context, state) => '/dashboard',
|
||||
),
|
||||
GoRoute(path: '/', redirect: (context, state) => '/dashboard'),
|
||||
ShellRoute(
|
||||
navigatorKey: _shellNavigatorKey,
|
||||
builder: (context, state, child) => MyHomePage(child: child),
|
||||
@@ -124,6 +127,17 @@ class _MyAppState extends State<MyApp> {
|
||||
path: '/dashboard',
|
||||
builder: (context, state) => const Dashboard(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/calculator',
|
||||
builder: (context, state) => const CalculatorPage(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'details',
|
||||
builder: (context, state) =>
|
||||
CalculatorDetailsPage(result: state.extra),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/logbook',
|
||||
redirect: (context, state) => '/logbook/entries',
|
||||
@@ -212,7 +226,10 @@ class _MyAppState extends State<MyApp> {
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(path: '/login', builder: (context, state) => const LoginScreen()),
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) => const LoginScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/settings',
|
||||
builder: (context, state) => const SettingsPage(),
|
||||
@@ -373,7 +390,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
TextSpan(
|
||||
children: const [
|
||||
TextSpan(text: "Mile"),
|
||||
TextSpan(text: "O", style: TextStyle(color: Colors.red)),
|
||||
TextSpan(
|
||||
text: "O",
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
TextSpan(text: "graph"),
|
||||
],
|
||||
style: const TextStyle(
|
||||
@@ -390,7 +410,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
onPressed: () => context.go('/more/settings'),
|
||||
icon: const Icon(Icons.settings),
|
||||
),
|
||||
IconButton(onPressed: auth.logout, icon: const Icon(Icons.logout)),
|
||||
IconButton(
|
||||
onPressed: auth.logout,
|
||||
icon: const Icon(Icons.logout),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: isWide
|
||||
@@ -448,7 +471,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
return Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.browserBack): const _BackIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.browserForward): const _ForwardIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.browserForward):
|
||||
const _ForwardIntent(),
|
||||
},
|
||||
child: Actions(
|
||||
actions: {
|
||||
@@ -474,7 +498,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) async {
|
||||
if (didPop) return;
|
||||
await _handleBackNavigation(allowExit: true, recordForward: false);
|
||||
await _handleBackNavigation(
|
||||
allowExit: true,
|
||||
recordForward: false,
|
||||
);
|
||||
},
|
||||
child: scaffold,
|
||||
),
|
||||
@@ -494,7 +521,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
|
||||
Widget _buildRailToggleButton(bool railExtended) {
|
||||
final collapseIcon = railExtended ? Icons.chevron_left : Icons.chevron_right;
|
||||
final collapseIcon = railExtended
|
||||
? Icons.chevron_left
|
||||
: Icons.chevron_right;
|
||||
final collapseLabel = railExtended ? 'Collapse' : 'Expand';
|
||||
|
||||
if (railExtended) {
|
||||
@@ -587,8 +616,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
final data = context.watch<DataService>();
|
||||
final notifications = data.notifications;
|
||||
final loading = data.isNotificationsLoading;
|
||||
final listHeight =
|
||||
isWide ? 380.0 : MediaQuery.of(context).size.height * 0.6;
|
||||
final listHeight = isWide
|
||||
? 380.0
|
||||
: MediaQuery.of(context).size.height * 0.6;
|
||||
|
||||
Widget body;
|
||||
if (loading && notifications.isEmpty) {
|
||||
@@ -628,9 +658,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
item.title.isNotEmpty
|
||||
? item.title
|
||||
: 'Notification',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
@@ -642,18 +670,15 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
_formatNotificationTime(item.createdAt!),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: () {
|
||||
final baseColor = Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.color;
|
||||
final baseColor = Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.color;
|
||||
if (baseColor == null) return null;
|
||||
final newAlpha =
|
||||
(baseColor.a * 0.7).clamp(0.0, 1.0);
|
||||
final newAlpha = (baseColor.a * 0.7)
|
||||
.clamp(0.0, 1.0);
|
||||
return baseColor.withValues(
|
||||
alpha: newAlpha,
|
||||
);
|
||||
@@ -666,10 +691,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: () => _dismissNotifications(
|
||||
context,
|
||||
[item.id],
|
||||
),
|
||||
onPressed: () =>
|
||||
_dismissNotifications(context, [item.id]),
|
||||
child: const Text('Dismiss'),
|
||||
),
|
||||
],
|
||||
@@ -695,19 +718,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
children: [
|
||||
Text(
|
||||
'Notifications',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: notifications.isEmpty
|
||||
? null
|
||||
: () => _dismissNotifications(
|
||||
context,
|
||||
notifications.map((e) => e.id).toList(),
|
||||
),
|
||||
context,
|
||||
notifications.map((e) => e.id).toList(),
|
||||
),
|
||||
child: const Text('Dismiss all'),
|
||||
),
|
||||
],
|
||||
@@ -729,9 +751,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
try {
|
||||
await context.read<DataService>().dismissNotifications(ids);
|
||||
} catch (e) {
|
||||
messenger?.showSnackBar(
|
||||
SnackBar(content: Text('Failed to dismiss: $e')),
|
||||
);
|
||||
messenger?.showSnackBar(SnackBar(content: Text('Failed to dismiss: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,9 +771,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
color: Colors.redAccent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 20,
|
||||
),
|
||||
constraints: const BoxConstraints(minWidth: 20),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
|
||||
Reference in New Issue
Block a user