Skip to content

Commit

Permalink
feat: #1492 - added call to "edit ingredients" from "edit product" (#…
Browse files Browse the repository at this point in the history
…1685)

Impacted files:
* `edit_ingredients_page.dart`: unrelated refactoring
* `edit_product_page.dart`: added call to "edit ingredients"
* `new_product_page.dart`: refactored
  • Loading branch information
monsieurtanuki authored Apr 28, 2022
1 parent 35ce58f commit 41c3a4d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ class _EditIngredientsPageState extends State<EditIngredientsPage> {
}

Future<void> _onSubmitField() async {
final User user = ProductQuery.getUser();

setState(() {
_updatingIngredients = true;
});

try {
await _updateIngredientsText(_controller.text, user);
await _updateIngredientsText(_controller.text);
} catch (error) {
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
_showError(appLocalizations.ingredients_editing_error);
Expand Down Expand Up @@ -144,7 +142,7 @@ class _EditIngredientsPageState extends State<EditIngredientsPage> {
}
}

Future<void> _updateIngredientsText(String ingredientsText, User user) async {
Future<void> _updateIngredientsText(String ingredientsText) async {
widget.product.ingredientsText = ingredientsText;
final LocalDatabase localDatabase = context.read<LocalDatabase>();
final bool savedAndRefreshed = await ProductRefresher().saveAndRefresh(
Expand Down
14 changes: 14 additions & 0 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/model/Product.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/edit_ingredients_page.dart';
import 'package:smooth_app/pages/product/nutrition_page_loaded.dart';
import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';

Expand Down Expand Up @@ -62,6 +63,19 @@ class _EditProductPageState extends State<EditProductPage> {
),
_ListTitleItem(
title: appLocalizations.edit_product_form_item_ingredients_title,
onTap: () async {
final bool? refreshed = await Navigator.push<bool>(
context,
MaterialPageRoute<bool>(
builder: (BuildContext context) => EditIngredientsPage(
product: widget.product,
),
),
);
if (refreshed ?? false) {
_changes++;
}
},
),
_ListTitleItem(
title: appLocalizations.edit_product_form_item_packaging_title,
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ class _ProductPageState extends State<ProductPage> {
EditProductPage(_product),
),
);
if (refreshed ?? false) {
setState(() {});
if (refreshed == true) {
await _refreshProduct(context);
}
},
),
Expand Down

0 comments on commit 41c3a4d

Please sign in to comment.