Skip to content

Commit

Permalink
feat: added dialog if users click on unselect image button #2427 (#3707)
Browse files Browse the repository at this point in the history
* feat: added dialog if users click on unselect image button #2427

Signed-off-by: BhuvanAde <[email protected]>

* Update packages/smooth_app/lib/l10n/app_en.arb

* Update packages/smooth_app/lib/l10n/app_en.arb

* feat: added dialog if users click on unselect image button #2427

Signed-off-by: BhuvanAde <[email protected]>

* Update packages/smooth_app/lib/l10n/app_en.arb

---------

Signed-off-by: BhuvanAde <[email protected]>
Co-authored-by: monsieurtanuki <[email protected]>
  • Loading branch information
BhuvanAde and monsieurtanuki authored Feb 14, 2023
1 parent f2ede98 commit 0dd30c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,10 @@
"@ask_me_later": {
"description": "Button to ignore the camera permission request"
},
"are_you_sure": "Are you sure?",
"@are_you_sure": {
"description": "Are you sure?"
},
"knowledge_panel_text_source": "Go further on {sourceName}",
"@knowledge_panel_text_source": {
"description": "Source field within a text knowledge panel.",
Expand Down
48 changes: 34 additions & 14 deletions packages/smooth_app/lib/pages/product/product_image_viewer.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: use_build_context_synchronously

import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -164,7 +166,7 @@ class _ProductImageViewerState extends State<ProductImageViewer> {
EditImageButton(
iconData: Icons.do_disturb_on,
label: appLocalizations.edit_photo_unselect_button_label,
onPressed: _actionUnselect,
onPressed: () => _actionUnselect(appLocalizations),
);

Widget _getGalleryButton(final AppLocalizations appLocalizations) =>
Expand All @@ -176,7 +178,6 @@ class _ProductImageViewerState extends State<ProductImageViewer> {

// TODO(monsieurtanuki): we should also suggest the existing image gallery
Future<File?> _actionNewImage() async {
// ignore: use_build_context_synchronously
if (!await ProductRefresher().checkIfLoggedIn(context)) {
return null;
}
Expand All @@ -189,11 +190,9 @@ class _ProductImageViewerState extends State<ProductImageViewer> {

Future<void> _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<int>? result = await LoadingDialog.run<List<int>>(
future: OpenFoodAPIClient.getProductImageIds(
_barcode,
Expand Down Expand Up @@ -237,7 +236,6 @@ class _ProductImageViewerState extends State<ProductImageViewer> {

Future<File?> _actionEditImage() async {
final NavigatorState navigatorState = Navigator.of(context);
// ignore: use_build_context_synchronously
if (!await ProductRefresher().checkIfLoggedIn(context)) {
return null;
}
Expand All @@ -262,7 +260,6 @@ class _ProductImageViewerState extends State<ProductImageViewer> {

// 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,
Expand All @@ -275,19 +272,42 @@ class _ProductImageViewerState extends State<ProductImageViewer> {
return null;
}

Future<void> _actionUnselect() async {
Future<void> _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<bool>(
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<File?> _openCropPage(
Expand Down

0 comments on commit 0dd30c4

Please sign in to comment.