Skip to content

Commit

Permalink
Use a SmoothFloatingSnackbar on all screens
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jan 9, 2025
1 parent 650d357 commit 34c8976
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 34 deletions.
38 changes: 38 additions & 0 deletions packages/smooth_app/lib/generic_lib/widgets/smooth_snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ class SmoothFloatingSnackbar extends SnackBar {
behavior: SnackBarBehavior.floating,
);

SmoothFloatingSnackbar.positive({
required BuildContext context,
required String text,
super.elevation,
super.padding,
super.width,
super.shape,
super.hitTestBehavior,
super.action,
super.actionOverflowThreshold,
super.showCloseIcon,
super.closeIconColor,
super.animation,
super.onVisible,
super.dismissDirection,
super.clipBehavior = Clip.hardEdge,
Duration? duration,
super.key,
}) : super(
margin: const EdgeInsetsDirectional.all(SMALL_SPACE),
duration: duration ??
(action != null
? const Duration(seconds: 10)
: SnackBarDuration.short),
behavior: SnackBarBehavior.floating,
backgroundColor:
context.extension<SmoothColorsThemeExtension>().success,
content: Row(
children: <Widget>[
Expanded(child: Text(text)),
const Icon(
Icons.check_circle,
color: Colors.white,
),
],
),
);

SmoothFloatingSnackbar.error({
required BuildContext context,
required String text,
Expand Down
3 changes: 2 additions & 1 deletion packages/smooth_app/lib/pages/offline_data_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/database/dao_product_last_access.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/helpers/app_helper.dart';
import 'package:smooth_app/pages/product/product_type_extensions.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
Expand Down Expand Up @@ -93,7 +94,7 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
await daoProductLastAccess.deleteAll();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(
appLocalizations.deleted_products(totalProductsDeleted),
),
Expand Down
6 changes: 4 additions & 2 deletions packages/smooth_app/lib/pages/personalized_ranking_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:smooth_app/database/local_database.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/duration_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/helpers/product_compatibility_helper.dart';
import 'package:smooth_app/pages/product/common/loading_status.dart';
import 'package:smooth_app/pages/product/common/product_list_item_simple.dart';
Expand Down Expand Up @@ -67,7 +68,7 @@ class _PersonalizedRankingPageState extends State<PersonalizedRankingPage>
}
if (added != null && added) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(
appLocalizations.added_to_list_msg,
),
Expand Down Expand Up @@ -231,7 +232,7 @@ class _PersonalizedRankingPageState extends State<PersonalizedRankingPage>
onDismissed: (final DismissDirection direction) {
_model.dismiss(matchedProduct.barcode);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(appLocalizations.product_removed_comparison),
duration: SnackBarDuration.medium,
),
Expand All @@ -250,6 +251,7 @@ class _PersonalizedRankingPageState extends State<PersonalizedRankingPage>
/// Virtual item in the list: either a product or a status header
class _VirtualItem {
const _VirtualItem.score(this.score) : status = null;

const _VirtualItem.status(this.status) : score = null;
final MatchedScoreV2? score;
final MatchedProductStatusV2? status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/helpers/entry_points_helper.dart';
import 'package:smooth_app/helpers/global_vars.dart';
import 'package:smooth_app/pages/preferences/user_preferences_item.dart';
Expand Down Expand Up @@ -46,13 +47,12 @@ class UserPreferencesRateUs extends StatelessWidget {

final ThemeData themeData = Theme.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(
appLocalizations.error_occurred,
textAlign: TextAlign.center,
style: TextStyle(color: themeData.colorScheme.surface),
),
behavior: SnackBarBehavior.floating,
backgroundColor: themeData.colorScheme.onSurface,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.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_snackbar.dart';
import 'package:smooth_app/pages/personalized_ranking_page.dart';
import 'package:smooth_app/pages/product/compare_products3_page.dart';
import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';
Expand Down Expand Up @@ -74,7 +75,7 @@ class ProductListItemPopupSideBySide extends ProductListItemPopupItem {
if (context.mounted) {
if (cache == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(
AppLocalizations.of(context).nutrition_cache_loading_error,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_app_logo.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_responsive.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/helpers/app_helper.dart';
import 'package:smooth_app/helpers/robotoff_insight_helper.dart';
import 'package:smooth_app/pages/all_product_list_modal.dart';
Expand Down Expand Up @@ -409,7 +410,7 @@ class _ProductListPageState extends State<ProductListPage>
}
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(
removed
? appLocalizations.product_removed_list
Expand Down Expand Up @@ -463,12 +464,12 @@ class _ProductListPageState extends State<ProductListPage>
if (!mounted) {
return;
}

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
appLocalizations.product_list_reloading_success_multiple(
products.length,
),
SmoothFloatingSnackbar.positive(
context: context,
text: appLocalizations.product_list_reloading_success_multiple(
products.length,
),
duration: SnackBarDuration.short,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:smooth_app/pages/user_management/login_page.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/query/search_products_manager.dart';
import 'package:smooth_app/services/smooth_services.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';

/// Refreshes a product on the BE then on the local database.
class ProductRefresher {
Expand Down Expand Up @@ -146,22 +145,9 @@ class ProductRefresher {
return false;
}
if (context.mounted) {
final ThemeData themeData = Theme.of(context);

ScaffoldMessenger.of(context).showSnackBar(
SmoothFloatingSnackbar(
content: Row(
children: <Widget>[
Expanded(child: Text(appLocalizations.product_refreshed)),
const Icon(
Icons.check_circle,
color: Colors.white,
),
],
),
backgroundColor:
themeData.extension<SmoothColorsThemeExtension>()!.green,
),
SmoothFloatingSnackbar.positive(
context: context, text: appLocalizations.product_refreshed),
);
}
return true;
Expand Down
10 changes: 5 additions & 5 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
Expand Down Expand Up @@ -62,10 +63,9 @@ class NutritionPageLoaded extends StatefulWidget {
if (context.mounted) {
if (cache == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
AppLocalizations.of(context).nutrition_cache_loading_error,
),
SmoothFloatingSnackbar.error(
context: context,
text: AppLocalizations.of(context).nutrition_cache_loading_error,
),
);
return;
Expand Down Expand Up @@ -536,7 +536,7 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded>
return false;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
// here I cheat and I reuse the only invalid case.
content: Text(appLocalizations.nutrition_page_invalid_number),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart';
import 'package:smooth_app/pages/product/common/search_helper.dart';
import 'package:smooth_app/pages/product/common/search_preloaded_item.dart';

Expand Down Expand Up @@ -198,7 +199,7 @@ class _SearchItemPasteFromClipboard extends StatelessWidget {
onData(data!.text!);
} else if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
SmoothFloatingSnackbar(
content: Text(localizations.no_data_available_in_clipboard),
),
);
Expand Down

0 comments on commit 34c8976

Please sign in to comment.