Skip to content

Commit

Permalink
fix: image edit and not logged-in user (#3689)
Browse files Browse the repository at this point in the history
* fix: image edit and not logged-in user

* fix: warning

* fix: image sign in
  • Loading branch information
Akashsri3bi authored Feb 9, 2023
1 parent 6588b0b commit 1c1acd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
3 changes: 0 additions & 3 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ class _EditProductPageState extends State<EditProductPage> {
subtitle:
appLocalizations.edit_product_form_item_photos_subtitle,
onTap: () async {
if (!await ProductRefresher().checkIfLoggedIn(context)) {
return;
}
await Navigator.push<void>(
context,
MaterialPageRoute<void>(
Expand Down
32 changes: 26 additions & 6 deletions packages/smooth_app/lib/pages/product/product_image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:smooth_app/generic_lib/widgets/picture_not_found.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/image/uploaded_image_gallery.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';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/tmp_crop_image/new_crop_page.dart';
Expand Down Expand Up @@ -174,14 +175,25 @@ class _ProductImageViewerState extends State<ProductImageViewer> {
);

// TODO(monsieurtanuki): we should also suggest the existing image gallery
Future<File?> _actionNewImage() async => confirmAndUploadNewPicture(
this,
imageField: _imageData.imageField,
barcode: _barcode,
);
Future<File?> _actionNewImage() async {
// ignore: use_build_context_synchronously
if (!await ProductRefresher().checkIfLoggedIn(context)) {
return null;
}
return confirmAndUploadNewPicture(
this,
imageField: _imageData.imageField,
barcode: _barcode,
);
}

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 @@ -225,7 +237,10 @@ 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;
}
// best possibility: with the crop parameters
// TODO(monsieurtanuki): maybe we should keep the big image locally, in order to avoid the server call?
final ProductImage? productImage = _getBestProductImage();
Expand All @@ -247,6 +262,7 @@ 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 @@ -261,6 +277,10 @@ class _ProductImageViewerState extends State<ProductImageViewer> {

Future<void> _actionUnselect() 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,
Expand Down

0 comments on commit 1c1acd8

Please sign in to comment.