Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of the added value to make this call different from the other.

);

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