add draft changes
All checks were successful
All checks were successful
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mileograph_flutter/objects/objects.dart';
|
||||
import 'package:mileograph_flutter/services/dataService.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -279,6 +280,11 @@ class _LegsPageState extends State<LegsPage> {
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Edit entry',
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () => context.push('/legs/edit/${leg.id}'),
|
||||
),
|
||||
Text(
|
||||
'${leg.mileage.toStringAsFixed(1)} mi',
|
||||
style:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ import 'package:mileograph_flutter/components/pages/legs.dart';
|
||||
import 'package:mileograph_flutter/services/apiService.dart';
|
||||
import 'package:mileograph_flutter/services/authservice.dart';
|
||||
import 'package:mileograph_flutter/services/dataService.dart';
|
||||
import 'package:mileograph_flutter/services/navigation_guard.dart';
|
||||
|
||||
import 'components/login/login.dart';
|
||||
import 'components/pages/dashboard.dart';
|
||||
@@ -100,6 +101,14 @@ class MyApp extends StatelessWidget {
|
||||
),
|
||||
GoRoute(path: '/trips', builder: (_, __) => TripsPage()),
|
||||
GoRoute(path: '/add', builder: (_, __) => NewEntryPage()),
|
||||
GoRoute(
|
||||
path: '/legs/edit/:id',
|
||||
builder: (_, state) {
|
||||
final idParam = state.pathParameters['id'];
|
||||
final legId = idParam == null ? null : int.tryParse(idParam);
|
||||
return NewEntryPage(editLegId: legId);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(path: '/login', builder: (_, __) => const LoginScreen()),
|
||||
@@ -180,12 +189,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
void _onItemTapped(int index, int currentIndex) {
|
||||
Future<void> _onItemTapped(int index, int currentIndex) async {
|
||||
if (index < 0 || index >= contentPages.length || index == currentIndex) {
|
||||
return;
|
||||
}
|
||||
context.push(contentPages[index]);
|
||||
_getIndexFromLocation(contentPages[index]);
|
||||
await NavigationGuard.attemptNavigation(() async {
|
||||
if (!mounted) return;
|
||||
context.go(contentPages[index]);
|
||||
});
|
||||
}
|
||||
|
||||
bool loggedIn = false;
|
||||
|
||||
40
lib/services/navigation_guard.dart
Normal file
40
lib/services/navigation_guard.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
typedef NavigationGuardCallback = Future<bool> Function();
|
||||
|
||||
class NavigationGuard {
|
||||
static NavigationGuardCallback? _callback;
|
||||
|
||||
static void register(NavigationGuardCallback callback) {
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
static void unregister(NavigationGuardCallback callback) {
|
||||
if (_callback == callback) {
|
||||
_callback = null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> attemptNavigation(
|
||||
Future<void> Function() performNavigation,
|
||||
) async {
|
||||
if (_promptActive) return;
|
||||
final cb = _callback;
|
||||
if (cb == null) {
|
||||
await performNavigation();
|
||||
return;
|
||||
}
|
||||
_promptActive = true;
|
||||
bool allow = false;
|
||||
try {
|
||||
allow = await cb();
|
||||
} catch (_) {
|
||||
allow = false;
|
||||
} finally {
|
||||
_promptActive = false;
|
||||
}
|
||||
if (allow) {
|
||||
await performNavigation();
|
||||
}
|
||||
}
|
||||
|
||||
static bool _promptActive = false;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 0.1.3+1
|
||||
version: 0.1.4+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
|
||||
Reference in New Issue
Block a user