Skip to content

Commit

Permalink
feat: added dialog if users click on unselect image button openfoodfa…
Browse files Browse the repository at this point in the history
…cts#2427

Signed-off-by: BhuvanAde <bhuvanadey@gmail.com>
  • Loading branch information
BhuvanAde committed Feb 13, 2023
1 parent bfefd90 commit 62cc9c3
Showing 1 changed file with 35 additions and 49 deletions.
84 changes: 35 additions & 49 deletions 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';
Expand Down Expand Up @@ -126,41 +128,7 @@ class _ProductImageViewerState extends State<ProductImageViewer> {
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<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)));
},
);
if (confirmed == true) {
await BackgroundTaskUnselect.addTask(
_barcode,
imageField: widget.imageField,
widget: this,
);
}
}),
child: _getUnselectImageButton(appLocalizations),
),
),
Expanded(
Expand Down Expand Up @@ -198,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 @@ -210,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 @@ -223,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 @@ -271,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 @@ -296,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 @@ -309,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 62cc9c3

Please sign in to comment.