-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 3771 - ingredient page now uses the same local/server buttons a…
…s gallery (#3852) New files: * `product_image_local_button.dart`: Button asking for a "local" photo (new from camera, existing from gallery). The code used to be in `product_image_view.dart`. * `product_image_server_button.dart`: Button asking for a "server" photo (taken from what was already uploaded). The code used to be in `product_image_view.dart`. Impacted files: * `edit_ingredients_page.dart`: minor refactoring * `ocr_widget.dart`: now using new buttons `ProductImageLocalButton` and `ProductImageServerButton` * `product_image_view.dart`: now using new buttons `ProductImageLocalButton` and `ProductImageServerButton`, whose code used to be there.
- Loading branch information
1 parent
d5a4d27
commit d2191ee
Showing
5 changed files
with
179 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/smooth_app/lib/pages/product/product_image_local_button.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/pages/image_crop_page.dart'; | ||
import 'package:smooth_app/pages/product/common/product_refresher.dart'; | ||
import 'package:smooth_app/pages/product/edit_image_button.dart'; | ||
|
||
/// Button asking for a "local" photo (new from camera, existing from gallery). | ||
class ProductImageLocalButton extends StatefulWidget { | ||
const ProductImageLocalButton({ | ||
required this.firstPhoto, | ||
required this.barcode, | ||
required this.imageField, | ||
}); | ||
|
||
final bool firstPhoto; | ||
final String barcode; | ||
final ImageField imageField; | ||
|
||
@override | ||
State<ProductImageLocalButton> createState() => | ||
_ProductImageLocalButtonState(); | ||
} | ||
|
||
class _ProductImageLocalButtonState extends State<ProductImageLocalButton> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
return EditImageButton( | ||
iconData: widget.firstPhoto ? Icons.add : Icons.add_a_photo, | ||
label: | ||
widget.firstPhoto ? appLocalizations.add : appLocalizations.capture, | ||
onPressed: () async => _actionNewImage(context), | ||
); | ||
} | ||
|
||
Future<void> _actionNewImage(final BuildContext context) async { | ||
final bool loggedIn = await ProductRefresher().checkIfLoggedIn(context); | ||
if (!loggedIn) { | ||
return; | ||
} | ||
if (context.mounted) { | ||
} else { | ||
return; | ||
} | ||
await confirmAndUploadNewPicture( | ||
this, | ||
imageField: widget.imageField, | ||
barcode: widget.barcode, | ||
); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/smooth_app/lib/pages/product/product_image_server_button.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; | ||
import 'package:smooth_app/generic_lib/loading_dialog.dart'; | ||
import 'package:smooth_app/pages/image/uploaded_image_gallery.dart'; | ||
import 'package:smooth_app/pages/product/common/product_refresher.dart'; | ||
import 'package:smooth_app/pages/product/edit_image_button.dart'; | ||
import 'package:smooth_app/query/product_query.dart'; | ||
|
||
/// Button asking for a "server" photo (taken from what was already uploaded). | ||
class ProductImageServerButton extends StatelessWidget { | ||
const ProductImageServerButton({ | ||
required this.barcode, | ||
required this.imageField, | ||
}); | ||
|
||
final String barcode; | ||
final ImageField imageField; | ||
|
||
@override | ||
Widget build(BuildContext context) => EditImageButton( | ||
iconData: Icons.image_search, | ||
label: AppLocalizations.of(context) | ||
.edit_photo_select_existing_button_label, | ||
onPressed: () async => _actionGallery(context), | ||
); | ||
|
||
Future<void> _actionGallery(final BuildContext context) async { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
if (!context.mounted) { | ||
return; | ||
} | ||
final bool loggedIn = await ProductRefresher().checkIfLoggedIn(context); | ||
if (!loggedIn) { | ||
return; | ||
} | ||
if (context.mounted) { | ||
} else { | ||
return; | ||
} | ||
final List<int>? result = await LoadingDialog.run<List<int>>( | ||
future: OpenFoodAPIClient.getProductImageIds( | ||
barcode, | ||
user: ProductQuery.getUser(), | ||
), | ||
context: context, | ||
title: appLocalizations.edit_photo_select_existing_download_label, | ||
); | ||
if (result == null) { | ||
return; | ||
} | ||
if (context.mounted) { | ||
} else { | ||
return; | ||
} | ||
if (result.isEmpty) { | ||
await showDialog<void>( | ||
context: context, | ||
builder: (BuildContext context) => SmoothAlertDialog( | ||
body: | ||
Text(appLocalizations.edit_photo_select_existing_downloaded_none), | ||
actionsAxis: Axis.vertical, | ||
positiveAction: SmoothActionButton( | ||
text: appLocalizations.okay, | ||
onPressed: () => Navigator.of(context).pop(), | ||
), | ||
), | ||
); | ||
return; | ||
} | ||
await Navigator.push<void>( | ||
context, | ||
MaterialPageRoute<void>( | ||
builder: (BuildContext context) => UploadedImageGallery( | ||
barcode: barcode, | ||
imageIds: result, | ||
imageField: imageField, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters