From 70ca39367dd990f307f6f07b09ab35547585beaf Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Wed, 8 Jan 2025 13:38:10 +0100 Subject: [PATCH] Add the upload indicator to the edit page (#6157) --- .../lib/helpers/provider_helper.dart | 18 ++++++++++++++++++ .../lib/pages/product/edit_product_page.dart | 16 +++++++++++++++- .../new_product_page_loading_indicator.dart | 12 +++++++++--- .../smooth_app/lib/widgets/smooth_banner.dart | 6 ++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/smooth_app/lib/helpers/provider_helper.dart b/packages/smooth_app/lib/helpers/provider_helper.dart index 84b86dbc5c5e..56282734fb7f 100644 --- a/packages/smooth_app/lib/helpers/provider_helper.dart +++ b/packages/smooth_app/lib/helpers/provider_helper.dart @@ -211,3 +211,21 @@ class _ConsumerValueNotifierFilterState, S> extension ValueNotifierExtensions on ValueNotifier { void emit(T value) => this.value = value; } + +extension ProviderExtension on BuildContext { + T? readSafe() { + try { + return read(); + } catch (_) { + return null; + } + } + + T? watchSafe() { + try { + return watch(); + } catch (_) { + return null; + } + } +} diff --git a/packages/smooth_app/lib/pages/product/edit_product_page.dart b/packages/smooth_app/lib/pages/product/edit_product_page.dart index b7467d23b4e1..0299db5024c7 100644 --- a/packages/smooth_app/lib/pages/product/edit_product_page.dart +++ b/packages/smooth_app/lib/pages/product/edit_product_page.dart @@ -5,6 +5,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/preferences/user_preferences.dart'; +import 'package:smooth_app/data_models/up_to_date_changes.dart'; import 'package:smooth_app/data_models/up_to_date_mixin.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; @@ -20,6 +21,7 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart'; import 'package:smooth_app/pages/product/gallery_view/product_image_gallery_view.dart'; import 'package:smooth_app/pages/product/nutrition_page_loaded.dart'; import 'package:smooth_app/pages/product/product_field_editor.dart'; +import 'package:smooth_app/pages/product/product_page/new_product_page_loading_indicator.dart'; import 'package:smooth_app/pages/product/simple_input_page.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; import 'package:smooth_app/resources/app_icons.dart' as icons; @@ -54,7 +56,7 @@ class _EditProductPageState extends State with UpToDateMixin { @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); - context.watch(); + final LocalDatabase localDatabase = context.watch(); refreshUpToDate(); final ThemeData theme = Theme.of(context); final bool lightTheme = context.lightTheme(); @@ -140,6 +142,12 @@ class _EditProductPageState extends State with UpToDateMixin { child: Scrollbar( controller: _controller, child: ListView( + padding: const EdgeInsetsDirectional.only( + top: SMALL_SPACE, + start: VERY_SMALL_SPACE, + end: VERY_SMALL_SPACE, + bottom: MEDIUM_SPACE, + ), controller: _controller, children: [ if (_ProductBarcode.isAValidBarcode(barcode)) @@ -299,6 +307,12 @@ class _EditProductPageState extends State with UpToDateMixin { ), ), ), + bottomNavigationBar: UpToDateChanges(localDatabase) + .hasNotTerminatedOperations(upToDateProduct.barcode!) + ? const ProductPageLoadingIndicator( + addSafeArea: true, + ) + : null, ); } diff --git a/packages/smooth_app/lib/pages/product/product_page/new_product_page_loading_indicator.dart b/packages/smooth_app/lib/pages/product/product_page/new_product_page_loading_indicator.dart index 62ab9ed935ab..445f580933ae 100644 --- a/packages/smooth_app/lib/pages/product/product_page/new_product_page_loading_indicator.dart +++ b/packages/smooth_app/lib/pages/product/product_page/new_product_page_loading_indicator.dart @@ -1,21 +1,26 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:provider/provider.dart'; import 'package:smooth_app/helpers/color_extension.dart'; +import 'package:smooth_app/helpers/provider_helper.dart'; import 'package:smooth_app/pages/product/product_page/new_product_page.dart'; import 'package:smooth_app/resources/app_animations.dart'; import 'package:smooth_app/themes/theme_provider.dart'; import 'package:smooth_app/widgets/smooth_banner.dart'; class ProductPageLoadingIndicator extends StatelessWidget { - const ProductPageLoadingIndicator({super.key}); + const ProductPageLoadingIndicator({ + this.addSafeArea = false, + super.key, + }); + + final bool addSafeArea; @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); final bool lightTheme = context.lightTheme(); - final Color color = context.watch().color ?? + final Color color = context.watchSafe()?.color ?? (lightTheme ? Colors.grey : Colors.grey[600]!); return SmoothBanner( @@ -31,6 +36,7 @@ class ProductPageLoadingIndicator extends StatelessWidget { contentColor: lightTheme ? null : Colors.grey[200], topShadow: true, content: appLocalizations.product_page_pending_operations_banner_message, + addSafeArea: addSafeArea, ); } } diff --git a/packages/smooth_app/lib/widgets/smooth_banner.dart b/packages/smooth_app/lib/widgets/smooth_banner.dart index 3b67afece8f9..f2414a5bc120 100644 --- a/packages/smooth_app/lib/widgets/smooth_banner.dart +++ b/packages/smooth_app/lib/widgets/smooth_banner.dart @@ -16,6 +16,7 @@ class SmoothBanner extends StatelessWidget { this.iconBackgroundColor, this.contentBackgroundColor, this.onDismissClicked, + this.addSafeArea = false, this.topShadow = false, super.key, }); @@ -28,6 +29,7 @@ class SmoothBanner extends StatelessWidget { /// If not null, a dismiss button is displayed final ValueChanged? onDismissClicked; final bool topShadow; + final bool addSafeArea; final Color? iconColor; final Color? iconBackgroundColor; @@ -39,6 +41,9 @@ class SmoothBanner extends StatelessWidget { @override Widget build(BuildContext context) { + final double bottomPadding = + addSafeArea ? MediaQuery.viewPaddingOf(context).bottom : 0.0; + Widget child = IntrinsicHeight( child: Row( children: [ @@ -116,6 +121,7 @@ class SmoothBanner extends StatelessWidget { color: contentColor ?? const Color(0xFF373737), ), ), + if (bottomPadding > 0) SizedBox(height: bottomPadding), ], ), ),