fix: navigation is more consistant

This commit is contained in:
2026-08-05 10:57:53 +02:00
parent 2896074ce4
commit 2c734493cf
10 changed files with 159 additions and 78 deletions
+5 -5
View File
@@ -53,13 +53,13 @@ class _BarScreenViewState extends State<BarScreenView> {
actions: [
IconButton(
tooltip: l10n.manageProducts,
onPressed: () => context.go('/products'),
onPressed: () => context.push('/products'),
icon: const Icon(Icons.inventory_2_outlined),
),
const SizedBox(width: 6),
IconButton(
tooltip: l10n.tabHistory,
onPressed: () => context.go('/history'),
onPressed: () => context.push('/history'),
icon: const Icon(Icons.history_rounded),
),
const SizedBox(width: 6),
@@ -71,7 +71,7 @@ class _BarScreenViewState extends State<BarScreenView> {
const SizedBox(width: 6),
IconButton(
tooltip: l10n.settings,
onPressed: () => context.go('/settings'),
onPressed: () => context.push('/settings'),
icon: const Icon(Icons.settings),
),
if (context.watch<PinLockViewModel>().isPinSet) ...[
@@ -230,7 +230,7 @@ class _ProductGrid extends StatelessWidget {
),
const SizedBox(height: 20),
FilledButton.icon(
onPressed: () => context.go('/products/new'),
onPressed: () => context.push('/products/new'),
icon: const Icon(Icons.add),
label: Text(l10n.addProduct),
),
@@ -324,7 +324,7 @@ class _ProductGrid extends StatelessWidget {
enabled: hasSelectedTab,
onTap: () => onProductTap(product),
onLongPress: () =>
context.go('/products/${product.id}/edit'),
context.push('/products/${product.id}/edit'),
);
},
);
+2 -1
View File
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../utils/app_update_util.dart';
import '../utils/navigation.dart';
import '../viewmodels/dev_menu_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
@@ -58,7 +59,7 @@ class _DevMenuViewState extends State<DevMenuView> {
return Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () => context.pop(),
onPressed: () => context.popOrGo('/bar'),
icon: const Icon(Icons.arrow_back),
),
title: Text(l10n.devMenu),
+2 -1
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../l10n/app_localizations.dart';
import '../utils/navigation.dart';
class ErrorScreenView extends StatelessWidget {
const ErrorScreenView({super.key});
@@ -14,7 +15,7 @@ class ErrorScreenView extends StatelessWidget {
return Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () => context.pop(),
onPressed: () => context.popOrGo('/bar'),
icon: const Icon(Icons.arrow_back),
),
title: Text(l10n.errorScreen),
+5 -10
View File
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:kooltab2/views/widgets/closed_tab_card.dart';
import 'package:provider/provider.dart';
import '../app/router.dart';
import '../utils/navigation.dart';
import '../viewmodels/history_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
@@ -61,16 +61,11 @@ class _HistoryScreenViewState extends State<HistoryScreenView> with RouteAware {
return Scaffold(
appBar: AppBar(
title: Row(
children: [
IconButton(
onPressed: () => context.go('/bar'),
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 5),
Text(l10n.tabHistory),
],
leading: IconButton(
onPressed: () => context.popOrGo('/bar'),
icon: const Icon(Icons.arrow_back),
),
title: Text(l10n.tabHistory),
actionsPadding: const EdgeInsets.symmetric(horizontal: 8),
actions: [
IconButton(
+11 -7
View File
@@ -1,7 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
@@ -12,6 +11,7 @@ import '../models/product.dart';
import '../viewmodels/product_list_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
import '../utils/navigation.dart';
class ProductFormView extends StatefulWidget {
final String? productId;
@@ -70,7 +70,7 @@ class _ProductFormViewState extends State<ProductFormView> {
context,
).showSnackBar(SnackBar(content: Text(l10n.productNotFound)));
context.go('/products');
_leaveProductForm();
return;
}
@@ -90,10 +90,14 @@ class _ProductFormViewState extends State<ProductFormView> {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.couldNotLoadProduct)));
context.go('/products');
_leaveProductForm();
}
}
void _leaveProductForm() {
context.popOrGo('/products');
}
@override
void dispose() {
_nameController.dispose();
@@ -214,7 +218,7 @@ class _ProductFormViewState extends State<ProductFormView> {
if (!mounted) return;
setState(() => _isSaving = false);
context.go('/products');
_leaveProductForm();
}
Future<void> _delete() async {
@@ -241,7 +245,7 @@ class _ProductFormViewState extends State<ProductFormView> {
},
);
if (confirmed != true) return;
if (confirmed != true || !mounted) return;
final viewModel = context.read<ProductListViewModel>();
@@ -258,7 +262,7 @@ class _ProductFormViewState extends State<ProductFormView> {
if (!mounted) return;
context.go('/products');
_leaveProductForm();
}
Widget _buildImagePicker(BuildContext context) {
@@ -328,7 +332,7 @@ class _ProductFormViewState extends State<ProductFormView> {
title: Text(title),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => context.go('/products'),
onPressed: _leaveProductForm,
),
actions: [
if (widget.isEditing)
+7 -11
View File
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
import '../viewmodels/product_list_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
import '../utils/navigation.dart';
class ProductListView extends StatefulWidget {
const ProductListView({super.key});
@@ -32,20 +33,15 @@ class _ProductListViewState extends State<ProductListView> {
return Scaffold(
appBar: AppBar(
title: Row(
children: [
IconButton(
onPressed: () => context.go('/bar'),
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 8),
Text(l10n.products),
],
leading: IconButton(
onPressed: () => context.popOrGo('/bar'),
icon: const Icon(Icons.arrow_back),
),
title: Text(l10n.products),
),
resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton.extended(
onPressed: () => context.go('/products/new'),
onPressed: () => context.push('/products/new'),
icon: const Icon(Icons.add),
label: Text(l10n.addProduct),
),
@@ -102,7 +98,7 @@ class _ProductListViewState extends State<ProductListView> {
),
),
trailing: const Icon(Icons.chevron_right),
onTap: () => context.go('/products/${product.id}/edit'),
onTap: () => context.push('/products/${product.id}/edit'),
),
);
},
+5 -9
View File
@@ -9,6 +9,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import '../models/settings.dart';
import '../utils/app_update_util.dart';
import '../utils/navigation.dart';
import '../viewmodels/pin_lock_view_model.dart';
import '../viewmodels/settings_view_model.dart';
import '../l10n/app_localizations.dart';
@@ -197,16 +198,11 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
return Scaffold(
appBar: AppBar(
title: Row(
children: [
IconButton(
onPressed: () => context.go('/bar'),
icon: const Icon(Icons.arrow_back),
),
const SizedBox(width: 5),
Text(l10n.settingsTitle),
],
leading: IconButton(
onPressed: () => context.popOrGo('/bar'),
icon: const Icon(Icons.arrow_back),
),
title: Text(l10n.settingsTitle),
),
body: Builder(
builder: (context) {
+40 -34
View File
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../utils/app_update_util.dart';
import '../utils/navigation.dart';
import '../viewmodels/update_progress_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
@@ -60,7 +60,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
TextButton(
onPressed: () {
Navigator.pop(context);
this.context.go('/bar');
this.context.popOrGo('/bar');
},
child: Text(l10n.later),
),
@@ -104,40 +104,46 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () => _showCancelDialog(),
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
if (!didPop) _showCancelDialog();
},
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () => _showCancelDialog(),
),
title: Text(l10n.updating),
centerTitle: true,
automaticallyImplyLeading: false,
),
title: Text(l10n.updating),
centerTitle: true,
automaticallyImplyLeading: false,
),
body: ListenableBuilder(
listenable: _vm,
builder: (context, child) {
return Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildHeader(),
const SizedBox(height: 40),
_buildProgress(_vm),
const SizedBox(height: 24),
_buildStatus(_vm),
const Spacer(),
_buildVersionInfo(_vm),
],
body: ListenableBuilder(
listenable: _vm,
builder: (context, child) {
return Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildHeader(),
const SizedBox(height: 40),
_buildProgress(_vm),
const SizedBox(height: 24),
_buildStatus(_vm),
const Spacer(),
_buildVersionInfo(_vm),
],
),
),
),
),
);
},
);
},
),
),
);
}
@@ -298,7 +304,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
onPressed: () {
Navigator.pop(context);
_vm.cancel();
this.context.go('/bar');
this.context.popOrGo('/bar');
},
child: Text(l10n.cancelUpdateAction),
),