Skip to content

Commit bfbc5a1

Browse files
fix: 7590 - "add product" - correct page title and logo beyond food + category (#7591)
Impacted files: * `add_new_product_page.dart`: now generating the page titles right in time, added fixed the logo * `prices_page.dart`: minor refactoring * `product_field_editor.dart`: now using the new `getStandardAddButtonLabel` method * `simple_input_page_helpers.dart`: added a `getStandardAddButtonLabel` method, that cover the standard "add a value" case * `smooth_screen_list_choice.dart`: minor refactoring * `smooth_topbar2.dart`: made `productType` required
1 parent 8b31224 commit bfbc5a1

6 files changed

Lines changed: 23 additions & 6 deletions

File tree

packages/smooth_app/lib/pages/prices/prices_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PricesPage extends StatelessWidget {
4343
title: appLocalizations.prices_list_title,
4444
subTitle: model.title,
4545
elevationOnScroll: true,
46+
productType: null,
4647
),
4748
injectPaddingInBody: model.displayEachProduct,
4849
belowTopBar: !model.displayEachProduct,

packages/smooth_app/lib/pages/product/add_new_product/add_new_product_page.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class _AddNewProductPageState extends State<AddNewProductPage>
8989
int _otherCount = 0;
9090

9191
/// The behavior is different for FOOD. And we don't know about it at first.
92+
///
93+
/// Be careful: as it can change (because `_inputProductType` can), don't
94+
/// cache anything, and always recompute anything based on `_probablyFood`.
9295
bool get _probablyFood =>
9396
(_inputProductType ?? ProductType.food) == ProductType.food;
9497

@@ -109,8 +112,6 @@ class _AddNewProductPageState extends State<AddNewProductPage>
109112

110113
final ProductList _history = ProductList.history();
111114

112-
List<String>? _appBarTitles;
113-
114115
final ProductFieldEditor _packagingEditor = ProductFieldPackagingEditor();
115116
final ProductFieldEditor _ingredientsEditor =
116117
ProductFieldOcrIngredientEditor();
@@ -236,7 +237,6 @@ class _AddNewProductPageState extends State<AddNewProductPage>
236237
@override
237238
Widget build(BuildContext context) {
238239
_colorScheme = Theme.of(context).colorScheme;
239-
_appBarTitles ??= _generateAppBarTitles(AppLocalizations.of(context));
240240

241241
context.watch<LocalDatabase>();
242242
refreshUpToDate();
@@ -251,13 +251,17 @@ class _AddNewProductPageState extends State<AddNewProductPage>
251251
.extension<SmoothColorsThemeExtension>();
252252
final bool lightTheme = context.lightTheme();
253253

254+
final List<String> appBarTitles = _generateAppBarTitles(
255+
AppLocalizations.of(context),
256+
);
254257
return WillPopScope2(
255258
onWillPop: () async => (await _onWillPop(), null),
256259
child: SmoothScaffold(
257260
appBar: SmoothTopBar2(
258-
title: _appBarTitles![_pageNumber],
261+
title: appBarTitles[_pageNumber],
259262
forceMultiLines: true,
260263
leadingAction: SmoothLeadingAction.back,
264+
productType: _inputProductType,
261265
topWidget: PreferredSize(
262266
preferredSize: const Size(
263267
double.infinity,

packages/smooth_app/lib/pages/product/product_field_editor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ProductFieldSimpleEditor extends ProductFieldEditor {
4242

4343
@override
4444
String getLabel(final AppLocalizations appLocalizations) =>
45-
helper.getAddButtonLabel(appLocalizations);
45+
helper.getStandardAddButtonLabel(appLocalizations);
4646

4747
@override
4848
Future<void> edit({

packages/smooth_app/lib/pages/product/simple_input/simple_input_page_helpers.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ abstract class AbstractSimpleInputPageHelper extends ChangeNotifier {
143143
) ||
144144
!const DeepCollectionEquality().equals(_terms, _initTerms);
145145

146+
/// Returns the label of the corresponding standard "add" button.
147+
///
148+
/// Typical use case: for category, that have a distinct label when the values
149+
/// are already set.
150+
String getStandardAddButtonLabel(final AppLocalizations appLocalizations) =>
151+
getAddButtonLabel(appLocalizations);
152+
146153
/// Returns the title on the main "edit product" page.
147154
String getTitle(final AppLocalizations appLocalizations);
148155

@@ -980,6 +987,10 @@ class SimpleInputPageCategoryHelper extends AbstractSimpleInputPageHelper {
980987
return appLocalizations.score_add_missing_product_category;
981988
}
982989

990+
@override
991+
String getStandardAddButtonLabel(final AppLocalizations appLocalizations) =>
992+
appLocalizations.score_add_missing_product_category;
993+
983994
@override
984995
String? getAddExplanationsTitle(AppLocalizations appLocalizations) =>
985996
appLocalizations.edit_product_form_item_categories_explanation_title;

packages/smooth_app/lib/widgets/selector_screen/smooth_screen_list_choice.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SmoothSelectorScreen<T> extends StatelessWidget {
6666
? SmoothLeadingAction.minimize
6767
: SmoothLeadingAction.close,
6868
elevationOnScroll: false,
69+
productType: null,
6970
),
7071
bottomBar: !provider.autoValidate
7172
? _SmoothSelectorScreenBottomBar<T>(

packages/smooth_app/lib/widgets/v2/smooth_topbar2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:vector_graphics/vector_graphics.dart';
1212
class SmoothTopBar2 extends StatefulWidget implements PreferredSizeWidget {
1313
const SmoothTopBar2({
1414
required this.title,
15+
required this.productType,
1516
this.subTitle,
1617
this.topWidget,
1718
this.leadingAction,
@@ -22,7 +23,6 @@ class SmoothTopBar2 extends StatefulWidget implements PreferredSizeWidget {
2223
this.elevationOnScroll = true,
2324
this.foregroundColor,
2425
this.backgroundColor,
25-
this.productType,
2626
this.theme,
2727
super.key,
2828
}) : assert(title.length > 0),

0 commit comments

Comments
 (0)