Skip to content

Commit

Permalink
feat: 3772 - access to nutrion photo from nutrition page (#3851)
Browse files Browse the repository at this point in the history
* feat: 3772 - access to nutrion photo from nutrition page

New file:
* `product_image_unswipeable_view.dart`: Display of the photo of a product image field.

Impacted files:
* `nutrition_page_loaded.dart`: added a "go to picture" button
* `product_image_swipeable_view.dart`: minor refactoring

* feat: 3772 - new view as a stateless widget

Impacted file:
* `product_image_unswipeable_view.dart`: now as a stateless widget.
  • Loading branch information
monsieurtanuki authored Apr 6, 2023
1 parent 54560ff commit d5a4d27
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
20 changes: 20 additions & 0 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/background/background_task_details.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
Expand All @@ -16,6 +17,7 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/nutrition_add_nutrient_button.dart';
import 'package:smooth_app/pages/product/nutrition_container.dart';
import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';
import 'package:smooth_app/pages/product/product_image_unswipeable_view.dart';
import 'package:smooth_app/pages/product/simple_input_number_field.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
Expand Down Expand Up @@ -134,6 +136,7 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
children.add(_switchNoNutrition(appLocalizations));

if (!_nutritionContainer.noNutritionData) {
children.add(_goToPicture(appLocalizations));
children.add(_getServingField(appLocalizations));
children.add(_getServingSwitch(appLocalizations));

Expand Down Expand Up @@ -453,6 +456,23 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
),
);

Widget _goToPicture(final AppLocalizations appLocalizations) => Padding(
padding: const EdgeInsets.symmetric(vertical: MEDIUM_SPACE),
child: SmoothLargeButtonWithIcon(
onPressed: () async => Navigator.push(
context,
MaterialPageRoute<void>(
builder: (_) => ProductImageUnswipeableView(
imageField: ImageField.NUTRITION,
product: _product,
),
),
),
icon: Icons.camera_alt,
text: appLocalizations.nutrition_facts_photo,
),
);

/// Returns `true` if any value differs with initial state.
bool _isEdited() {
if (_servingController != null && _servingController!.valueHasChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/product_image_viewer.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

///Widget to display swipeable product images of particular category,
///Opens product image with [initialImageIndex].
/// Widget to display swipeable product images of particular category.
///
/// Opens product image with [initialImageIndex].
/// See also [ProductImageUnswipeableView].
class ProductImageSwipeableView extends StatefulWidget {
const ProductImageSwipeableView({
super.key,
required this.product,
required this.initialImageIndex,
});

final Product product;
final int initialImageIndex;

@override
State<ProductImageSwipeableView> createState() =>
_ProductImageSwipeableViewState();
Expand Down Expand Up @@ -79,10 +83,13 @@ class _ProductImageSwipeableViewState extends State<ProductImageSwipeableView> {
elevation: 0,
title: ValueListenableBuilder<int>(
valueListenable: _currentImageDataIndex,
builder: (_, int index, __) => Text(getImagePageTitle(
appLocalizations,
_imageDataList[index].imageField,
)),
builder: (_, int index, __) => Text(
getImagePageTitle(
appLocalizations,
_imageDataList[index].imageField,
),
maxLines: 2,
),
),
leading: SmoothBackButton(
iconColor: Colors.white,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_back_button.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/product_image_viewer.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Display of the photo of a product image field.
///
/// See also [ProductImageSwipeableView].
class ProductImageUnswipeableView extends StatelessWidget {
const ProductImageUnswipeableView({
super.key,
required this.product,
required this.imageField,
});

final Product product;
final ImageField imageField;

@override
Widget build(BuildContext context) => SmoothScaffold(
appBar: AppBar(
backgroundColor: Colors.black,
foregroundColor: WHITE_COLOR,
elevation: 0,
title: Text(
getImagePageTitle(AppLocalizations.of(context), imageField),
maxLines: 2,
),
leading: SmoothBackButton(
iconColor: Colors.white,
onPressed: () => Navigator.maybePop(context),
),
),
body: ProductImageViewer(
product: product,
imageField: imageField,
),
);
}

0 comments on commit d5a4d27

Please sign in to comment.