fix navbar freezing fix
Some checks failed
Release / meta (push) Failing after 9s
Release / android-build (push) Has been skipped
Release / linux-build (push) Has been skipped
Release / release-dev (push) Has been skipped
Release / release-master (push) Has been skipped

This commit is contained in:
2025-12-17 17:41:09 +00:00
parent a9e0cdbe1b
commit 587933fa50
7 changed files with 182 additions and 63 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:mileograph_flutter/components/calculator/calculator.dart';
import 'package:mileograph_flutter/components/pages/traction.dart';

View File

@@ -10,6 +10,7 @@ class NewEntryPage extends StatefulWidget {
}
class _NewEntryPageState extends State<NewEntryPage> {
late final NavigationGuardCallback _exitGuard;
final _formKey = GlobalKey<FormState>();
DateTime _selectedDate = DateTime.now();
TimeOfDay _selectedTime = TimeOfDay.now();
@@ -40,7 +41,8 @@ class _NewEntryPageState extends State<NewEntryPage> {
@override
void initState() {
super.initState();
NavigationGuard.register(_handleExitIntent);
_exitGuard = _handleExitIntent;
NavigationGuard.register(_exitGuard);
// legacy single-draft auto-save listeners removed in favor of explicit multi-draft flow
Future.microtask(() {
if (!mounted) return;
@@ -58,7 +60,7 @@ class _NewEntryPageState extends State<NewEntryPage> {
@override
void dispose() {
NavigationGuard.unregister(_handleExitIntent);
NavigationGuard.unregister(_exitGuard);
_startController.dispose();
_endController.dispose();
_headcodeController.dispose();
@@ -586,7 +588,12 @@ class _NewEntryPageState extends State<NewEntryPage> {
if (didPop) return;
final allow = await _handleExitIntent();
if (allow && context.mounted) {
Navigator.of(context).maybePop();
final router = GoRouter.of(context);
if (router.canPop()) {
context.pop();
} else {
context.go('/');
}
}
},
child: Scaffold(
@@ -597,7 +604,12 @@ class _NewEntryPageState extends State<NewEntryPage> {
onPressed: () async {
if (!await _handleExitIntent()) return;
if (!context.mounted) return;
Navigator.of(context).maybePop();
final router = GoRouter.of(context);
if (router.canPop()) {
context.pop();
} else {
context.go('/');
}
},
),
title: const Text('Edit entry'),