fix: navigation is more consistant
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user