Skip to content

Commit

Permalink
fix: 4925 - consistency for "edit product" app bars (#4931)
Browse files Browse the repository at this point in the history
Impacted files:
* `add_basic_details_page.dart`: now using new method `buildEditProductAppBar`
* `add_other_details_page.dart`: now using new method `buildEditProductAppBar`; removed an irrelevant barcode display
* `edit_new_packagings.dart`: now using new method `buildEditProductAppBar`
* `edit_ocr_page.dart`: now using new method `buildEditProductAppBar`
* `edit_product_page.dart`: removed inconsistent `fullScreenDialog:true` parameters
* `nutrition_page_loaded.dart`: now using new method `buildEditProductAppBar`; removed inconsistent `fullScreenDialog:true` parameters
* `product_cards_helper.dart`: new method `buildEditProductAppBar` instead of `buildProductTitle`
* `product_field_editor.dart`: removed inconsistent `fullScreenDialog:true` parameters
* `product_image_gallery_view.dart`: now using new method `buildEditProductAppBar`
* `product_image_other_page.dart`: now using new method `buildEditProductAppBar`
* `simple_input_page.dart`: now using new method `buildEditProductAppBar`
* `simple_input_widget.dart`: now we don't display the widget title on a single widget page - in order to avoid title redundancy
  • Loading branch information
monsieurtanuki authored Jan 7, 2024
1 parent 64481bb commit c76715d
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 104 deletions.
27 changes: 19 additions & 8 deletions packages/smooth_app/lib/helpers/product_cards_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
import 'package:smooth_app/helpers/ui_helpers.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';

Widget buildProductTitle(
final Product product,
final AppLocalizations appLocalizations,
) =>
Text(
getProductNameAndBrands(product, appLocalizations),
overflow: TextOverflow.ellipsis,
maxLines: 1,
SmoothAppBar buildEditProductAppBar({
required final BuildContext context,
required final String title,
required final Product product,
}) =>
SmoothAppBar(
centerTitle: false,
title: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subTitle: Text(
getProductNameAndBrands(product, AppLocalizations.of(context)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
ignoreSemanticsForSubtitle: true,
);

String getProductNameAndBrands(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Full page display of a raw product image.
Expand All @@ -19,10 +18,10 @@ class ProductImageOtherPage extends StatelessWidget {
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothScaffold(
appBar: SmoothAppBar(
centerTitle: false,
title: Text(appLocalizations.edit_product_form_item_photos_title),
subTitle: buildProductTitle(product, appLocalizations),
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.edit_product_form_item_photos_title,
product: product,
),
body: Image(
image: NetworkImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/multilingual_helper.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Input of a product's basic details, like name, quantity and brands.
Expand Down Expand Up @@ -91,10 +90,10 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
centerTitle: false,
title: Text(appLocalizations.basic_details),
subTitle: buildProductTitle(widget.product, appLocalizations),
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.basic_details,
product: widget.product,
),
body: Form(
key: _formKey,
Expand Down
20 changes: 4 additions & 16 deletions packages/smooth_app/lib/pages/product/add_other_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/common/product_buttons.dart';
import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Input of a product's less significant details, like website.
Expand Down Expand Up @@ -58,12 +57,10 @@ class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
onWillPop: () async => _mayExitPage(saving: false),
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
centerTitle: false,
title:
Text(appLocalizations.edit_product_form_item_other_details_title),
subTitle: buildProductTitle(widget.product, appLocalizations),
ignoreSemanticsForSubtitle: true,
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.edit_product_form_item_other_details_title,
product: widget.product,
),
body: Form(
key: _formKey,
Expand All @@ -75,15 +72,6 @@ class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
padding: EdgeInsets.symmetric(horizontal: size.width * 0.05),
child: Column(
children: <Widget>[
ExcludeSemantics(
child: Text(
appLocalizations.barcode_barcode(_product.barcode!),
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
SizedBox(height: _heightSpace),
SmoothTextFormField(
controller: _websiteController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/simple_input_number_field.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/themes/color_schemes.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Edit display of a product packagings (the new api V3 version).
Expand Down Expand Up @@ -188,9 +187,11 @@ class _EditNewPackagingsState extends State<EditNewPackagings>
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
title: Text(appLocalizations.edit_packagings_title),
subTitle: buildProductTitle(upToDateProduct, appLocalizations)),
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.edit_packagings_title,
product: upToDateProduct,
),
body: ListView(
padding: const EdgeInsets.only(top: LARGE_SPACE),
children: children,
Expand Down
35 changes: 4 additions & 31 deletions packages/smooth_app/lib/pages/product/edit_ocr_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui' show ImageFilter;

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
Expand All @@ -21,7 +19,6 @@ import 'package:smooth_app/pages/product/multilingual_helper.dart';
import 'package:smooth_app/pages/product/ocr_helper.dart';
import 'package:smooth_app/pages/product/product_image_local_button.dart';
import 'package:smooth_app/pages/product/product_image_server_button.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Editing with OCR a product field and the corresponding image.
Expand Down Expand Up @@ -131,37 +128,13 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
_multilingualHelper.getCurrentLanguage(),
);

final TextStyle appbarTextStyle = TextStyle(shadows: <Shadow>[
Shadow(
color: Theme.of(context).colorScheme.brightness == Brightness.light
? Colors.white
: Colors.black,
offset: const Offset(0.5, 0.5),
blurRadius: 5.0,
)
]);

// TODO(monsieurtanuki): add WillPopScope / MayExitPage system
return SmoothScaffold(
extendBodyBehindAppBar: true,
appBar: SmoothAppBar(
centerTitle: false,
title: Text(
_helper.getTitle(appLocalizations),
style: appbarTextStyle,
),
subTitle: DefaultTextStyle(
style: appbarTextStyle,
child: buildProductTitle(upToDateProduct, appLocalizations)),
backgroundColor: Colors.transparent,
flexibleSpace: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Container(
color: Colors.transparent,
),
),
),
appBar: buildEditProductAppBar(
context: context,
title: _helper.getTitle(appLocalizations),
product: upToDateProduct,
),
body: Stack(
children: <Widget>[
Expand Down
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 @@ -154,7 +154,6 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
ProductImageGalleryView(
product: upToDateProduct,
),
fullscreenDialog: true,
),
);
},
Expand Down Expand Up @@ -250,7 +249,6 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
context,
MaterialPageRoute<void>(
builder: (_) => AddOtherDetailsPage(upToDateProduct),
fullscreenDialog: true,
),
);
},
Expand Down Expand Up @@ -308,7 +306,6 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
helpers: helpers,
product: upToDateProduct,
),
fullscreenDialog: true,
),
);
},
Expand Down
12 changes: 4 additions & 8 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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/simple_input_number_field.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Actual nutrition page, with data already loaded.
Expand Down Expand Up @@ -74,7 +73,6 @@ class NutritionPageLoaded extends StatefulWidget {
cache.orderedNutrients,
isLoggedInMandatory: isLoggedInMandatory,
),
fullscreenDialog: true,
),
);
}
Expand Down Expand Up @@ -196,12 +194,10 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded>
onWillPop: () async => _mayExitPage(saving: false),
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
title: AutoSizeText(
appLocalizations.nutrition_page_title,
maxLines: 1,
),
subTitle: buildProductTitle(upToDateProduct, appLocalizations),
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.nutrition_page_title,
product: upToDateProduct,
),
body: Padding(
padding: const EdgeInsets.symmetric(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class ProductFieldSimpleEditor extends ProductFieldEditor {
helper: helper,
product: product,
),
fullscreenDialog: true,
),
);
}
Expand Down Expand Up @@ -163,7 +162,6 @@ class ProductFieldPackagingEditor extends ProductFieldEditor {
product: product,
isLoggedInMandatory: isLoggedInMandatory,
),
fullscreenDialog: true,
),
);
}
Expand Down Expand Up @@ -229,7 +227,6 @@ abstract class ProductFieldOcrEditor extends ProductFieldEditor {
helper: helper,
isLoggedInMandatory: isLoggedInMandatory,
),
fullscreenDialog: true,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/product_image_swipeable_view.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/slivers.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Display of the main 4 pictures of a product, with edit options.
Expand Down Expand Up @@ -52,10 +51,10 @@ class _ProductImageGalleryViewState extends State<ProductImageGalleryView>
context.watch<LocalDatabase>();
refreshUpToDate();
return SmoothScaffold(
appBar: SmoothAppBar(
centerTitle: false,
title: Text(appLocalizations.edit_product_form_item_photos_title),
subTitle: buildProductTitle(upToDateProduct, appLocalizations),
appBar: buildEditProductAppBar(
context: context,
title: appLocalizations.edit_product_form_item_photos_title,
product: upToDateProduct,
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
Expand Down
15 changes: 7 additions & 8 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:smooth_app/pages/product/common/product_buttons.dart';
import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/pages/product/simple_input_widget.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Simple input page: we have a list of terms, we add, we remove, we save.
Expand Down Expand Up @@ -54,8 +53,10 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final List<Widget> simpleInputs = <Widget>[];
final List<String> titles = <String>[];

for (int i = 0; i < widget.helpers.length; i++) {
titles.add(widget.helpers[i].getTitle(appLocalizations));
simpleInputs.add(
Padding(
padding: i == 0
Expand All @@ -79,6 +80,7 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
helper: widget.helpers[i],
product: widget.product,
controller: _controllers[i],
displayTitle: widget.helpers.length > 1,
),
),
),
Expand All @@ -91,13 +93,10 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
centerTitle: false,
title: buildProductTitle(widget.product, appLocalizations),
subTitle: widget.product.barcode != null
? ExcludeSemantics(
excluding: true, child: Text(widget.product.barcode!))
: null,
appBar: buildEditProductAppBar(
context: context,
title: titles.join(', '),
product: widget.product,
),
body: Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
Expand Down
19 changes: 11 additions & 8 deletions packages/smooth_app/lib/pages/product/simple_input_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class SimpleInputWidget extends StatefulWidget {
required this.helper,
required this.product,
required this.controller,
required this.displayTitle,
});

final AbstractSimpleInputPageHelper helper;
final Product product;
final TextEditingController controller;
final bool displayTitle;

@override
State<SimpleInputWidget> createState() => _SimpleInputWidgetState();
Expand Down Expand Up @@ -64,15 +66,16 @@ class _SimpleInputWidgetState extends State<SimpleInputWidget> {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: widget.helper.getIcon(),
minLeadingWidth: 0.0,
horizontalTitleGap: 12.0,
title: Text(
widget.helper.getTitle(appLocalizations),
style: themeData.textTheme.displaySmall,
if (widget.displayTitle)
ListTile(
leading: widget.helper.getIcon(),
minLeadingWidth: 0.0,
horizontalTitleGap: 12.0,
title: Text(
widget.helper.getTitle(appLocalizations),
style: themeData.textTheme.displaySmall,
),
),
),
if (explanations != null) ExplanationWidget(explanations),
LayoutBuilder(
builder: (_, BoxConstraints constraints) {
Expand Down

0 comments on commit c76715d

Please sign in to comment.