Skip to content

Commit

Permalink
fix: Conflicting task names for ingredients and packaging (#2950)
Browse files Browse the repository at this point in the history
* fix conflicting task names for
packaging and ingredeints

* fix spelling mistake
  • Loading branch information
AshAman999 authored Sep 6, 2022
1 parent b163db9 commit 5f575a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 6 additions & 3 deletions packages/smooth_app/lib/helpers/background_task_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ const String NUTRITION_EDIT = 'NUTRITION_EDIT';
/// Constant for basic details edit task
const String BASIC_DETAILS = 'BASIC_DETAILS';

/// Constnat for packaging edit task
const String PACKAGING_EDIT = 'PACKAGING_EDIT';

/// Response code sent by the server in case of a success
const int SUCESS_CODE = 1;
const int SUCCESS_CODE = 1;

/// Runs whenever a task is started in the background.
/// Whatever invoked with TaskManager.addTask() will be run in this method.
Expand Down Expand Up @@ -84,7 +87,7 @@ Future<TaskResult> otherDetails(
final ProductResult queryResult =
await OpenFoodAPIClient.getProduct(configuration);

if (queryResult.status == SUCESS_CODE) {
if (queryResult.status == SUCCESS_CODE) {
final Product? product = queryResult.product;
if (product != null) {
await daoProduct.put(product);
Expand Down Expand Up @@ -129,7 +132,7 @@ Future<TaskResult> uploadImage(

final ProductResult queryResult =
await OpenFoodAPIClient.getProduct(configuration);
if (queryResult.status == SUCESS_CODE) {
if (queryResult.status == SUCCESS_CODE) {
final Product? product = queryResult.product;
if (product != null) {
await daoProduct.put(product);
Expand Down
21 changes: 13 additions & 8 deletions packages/smooth_app/lib/pages/product/edit_ingredients_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class _EditOcrPageState extends State<EditOcrPage> {
_controller.text = _helper.getText(_product);
}

Future<void> _onSubmitField() async {
Future<void> _onSubmitField(ImageField imageField) async {
setState(() => _updatingText = true);
final UpToDateProductProvider provider =
context.read<UpToDateProductProvider>();
await _updateText(_controller.text, provider);
await _updateText(_controller.text, provider, imageField);
setState(() => _updatingText = false);
}

Expand Down Expand Up @@ -124,8 +124,8 @@ class _EditOcrPageState extends State<EditOcrPage> {
}
}

Future<bool> _updateText(
final String text, UpToDateProductProvider provider) async {
Future<bool> _updateText(final String text, UpToDateProductProvider provider,
ImageField imageField) async {
final LocalDatabase localDatabase = context.read<LocalDatabase>();
final DaoProduct daoProduct = DaoProduct(localDatabase);
Product changedProduct = Product(barcode: _product.barcode);
Expand All @@ -134,8 +134,12 @@ class _EditOcrPageState extends State<EditOcrPage> {
cachedProduct = _helper.getMinimalistProduct(cachedProduct, text);
}
changedProduct = _helper.getMinimalistProduct(changedProduct, text);
final String uniqueId =
String uniqueId =
UniqueIdGenerator.generateUniqueId(_product.barcode!, INGREDIENT_EDIT);
if (_helper.getImageField().value == ImageField.PACKAGING.value) {
uniqueId =
UniqueIdGenerator.generateUniqueId(_product.barcode!, PACKAGING_EDIT);
}
final BackgroundOtherDetailsInput backgroundOtherDetailsInput =
BackgroundOtherDetailsInput(
processName: PRODUCT_EDIT_TASK,
Expand Down Expand Up @@ -283,7 +287,7 @@ class _OcrWidget extends StatelessWidget {
final TextEditingController controller;
final bool updatingText;
final Future<void> Function(bool) onTapGetImage;
final Future<void> Function() onSubmitField;
final Future<void> Function(ImageField) onSubmitField;
final bool hasImageProvider;
final Product product;
final OcrHelper helper;
Expand Down Expand Up @@ -350,7 +354,8 @@ class _OcrWidget extends StatelessWidget {
),
maxLines: null,
textInputAction: TextInputAction.done,
onSubmitted: (_) => onSubmitField,
onSubmitted: (_) =>
onSubmitField(helper.getImageField()),
),
const SizedBox(height: SMALL_SPACE),
ExplanationWidget(
Expand All @@ -366,7 +371,7 @@ class _OcrWidget extends StatelessWidget {
positiveAction: SmoothActionButton(
text: appLocalizations.save,
onPressed: () async {
await onSubmitField();
await onSubmitField(helper.getImageField());
//ignore: use_build_context_synchronously
Navigator.pop(context);
},
Expand Down

0 comments on commit 5f575a3

Please sign in to comment.