diff --git a/packages/smooth_app/lib/pages/product/product_image_viewer.dart b/packages/smooth_app/lib/pages/product/product_image_viewer.dart index 50611a24f5e..5661be34a1b 100644 --- a/packages/smooth_app/lib/pages/product/product_image_viewer.dart +++ b/packages/smooth_app/lib/pages/product/product_image_viewer.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:io'; import 'package:flutter/material.dart'; @@ -126,41 +128,7 @@ class _ProductImageViewerState extends State { child: Padding( padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE), - child: (imageProvider == null) - ? Container() - : EditImageButton( - iconData: Icons.do_disturb_on, - label: appLocalizations - .edit_photo_unselect_button_label, - onPressed: () async { - final bool? confirmed = await showDialog( - context: context, - builder: (BuildContext context) { - return SmoothAlertDialog( - title: - appLocalizations.confirm_button_label, - body: Text( - appLocalizations.are_you_sure, - ), - close: true, - positiveAction: SmoothActionButton( - text: appLocalizations.yes, - onPressed: () => - Navigator.of(context).pop(true)), - negativeAction: SmoothActionButton( - text: appLocalizations.no, - onPressed: () => Navigator.of(context) - .pop(false))); - }, - ); - if (confirmed == true) { - await BackgroundTaskUnselect.addTask( - _barcode, - imageField: widget.imageField, - widget: this, - ); - } - }), + child: _getUnselectImageButton(appLocalizations), ), ), Expanded( @@ -198,7 +166,7 @@ class _ProductImageViewerState extends State { EditImageButton( iconData: Icons.do_disturb_on, label: appLocalizations.edit_photo_unselect_button_label, - onPressed: _actionUnselect, + onPressed: () => _actionUnselect(appLocalizations), ); Widget _getGalleryButton(final AppLocalizations appLocalizations) => @@ -210,7 +178,6 @@ class _ProductImageViewerState extends State { // TODO(monsieurtanuki): we should also suggest the existing image gallery Future _actionNewImage() async { - // ignore: use_build_context_synchronously if (!await ProductRefresher().checkIfLoggedIn(context)) { return null; } @@ -223,11 +190,9 @@ class _ProductImageViewerState extends State { Future _actionGallery() async { final AppLocalizations appLocalizations = AppLocalizations.of(context); - // ignore: use_build_context_synchronously if (!await ProductRefresher().checkIfLoggedIn(context)) { return; } - // ignore: use_build_context_synchronously final List? result = await LoadingDialog.run>( future: OpenFoodAPIClient.getProductImageIds( _barcode, @@ -271,7 +236,6 @@ class _ProductImageViewerState extends State { Future _actionEditImage() async { final NavigatorState navigatorState = Navigator.of(context); - // ignore: use_build_context_synchronously if (!await ProductRefresher().checkIfLoggedIn(context)) { return null; } @@ -296,7 +260,6 @@ class _ProductImageViewerState extends State { // but if not possible, get the best picture from the server. final String? imageUrl = _imageData.getImageUrl(ImageSize.ORIGINAL); - // ignore: use_build_context_synchronously imageFile = await downloadImageUrl( context, imageUrl, @@ -309,19 +272,42 @@ class _ProductImageViewerState extends State { return null; } - Future _actionUnselect() async { + Future _actionUnselect(final AppLocalizations appLocalizations) async { final NavigatorState navigatorState = Navigator.of(context); - // ignore: use_build_context_synchronously + if (!await ProductRefresher().checkIfLoggedIn(context)) { return; } - await BackgroundTaskUnselect.addTask( - _barcode, - imageField: widget.imageField, - widget: this, + + final bool? confirmed = await showDialog( + context: context, + builder: (BuildContext context) { + return SmoothAlertDialog( + title: appLocalizations.confirm_button_label, + body: Text( + appLocalizations.are_you_sure, + ), + close: true, + positiveAction: SmoothActionButton( + text: appLocalizations.yes, + onPressed: () => Navigator.of(context).pop(true), + ), + negativeAction: SmoothActionButton( + text: appLocalizations.no, + onPressed: () => Navigator.of(context).pop(false), + ), + ); + }, ); - _localDatabase.notifyListeners(); - navigatorState.pop(); + if (confirmed == true) { + await BackgroundTaskUnselect.addTask( + _barcode, + imageField: widget.imageField, + widget: this, + ); + _localDatabase.notifyListeners(); + navigatorState.pop(); + } } Future _openCropPage(