Skip to content

Commit

Permalink
Add the upload indicator to the edit page (#6157)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Jan 8, 2025
1 parent d389367 commit 70ca393
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
18 changes: 18 additions & 0 deletions packages/smooth_app/lib/helpers/provider_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,21 @@ class _ConsumerValueNotifierFilterState<T extends ValueNotifier<S>, S>
extension ValueNotifierExtensions<T> on ValueNotifier<T> {
void emit(T value) => this.value = value;
}

extension ProviderExtension on BuildContext {
T? readSafe<T>() {
try {
return read<T>();
} catch (_) {
return null;
}
}

T? watchSafe<T>() {
try {
return watch<T>();
} catch (_) {
return null;
}
}
}
16 changes: 15 additions & 1 deletion packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -54,7 +56,7 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
context.watch<LocalDatabase>();
final LocalDatabase localDatabase = context.watch<LocalDatabase>();
refreshUpToDate();
final ThemeData theme = Theme.of(context);
final bool lightTheme = context.lightTheme();
Expand Down Expand Up @@ -140,6 +142,12 @@ class _EditProductPageState extends State<EditProductPage> 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: <Widget>[
if (_ProductBarcode.isAValidBarcode(barcode))
Expand Down Expand Up @@ -299,6 +307,12 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
),
),
),
bottomNavigationBar: UpToDateChanges(localDatabase)
.hasNotTerminatedOperations(upToDateProduct.barcode!)
? const ProductPageLoadingIndicator(
addSafeArea: true,
)
: null,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProductPageCompatibility>().color ??
final Color color = context.watchSafe<ProductPageCompatibility>()?.color ??
(lightTheme ? Colors.grey : Colors.grey[600]!);

return SmoothBanner(
Expand All @@ -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,
);
}
}
6 changes: 6 additions & 0 deletions packages/smooth_app/lib/widgets/smooth_banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SmoothBanner extends StatelessWidget {
this.iconBackgroundColor,
this.contentBackgroundColor,
this.onDismissClicked,
this.addSafeArea = false,
this.topShadow = false,
super.key,
});
Expand All @@ -28,6 +29,7 @@ class SmoothBanner extends StatelessWidget {
/// If not null, a dismiss button is displayed
final ValueChanged<SmoothBannerDismissEvent>? onDismissClicked;
final bool topShadow;
final bool addSafeArea;

final Color? iconColor;
final Color? iconBackgroundColor;
Expand All @@ -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: <Widget>[
Expand Down Expand Up @@ -116,6 +121,7 @@ class SmoothBanner extends StatelessWidget {
color: contentColor ?? const Color(0xFF373737),
),
),
if (bottomPadding > 0) SizedBox(height: bottomPadding),
],
),
),
Expand Down

0 comments on commit 70ca393

Please sign in to comment.