Skip to content

Commit

Permalink
fix: 6281 LateError: LateInitializationError (#6287)
Browse files Browse the repository at this point in the history
* Multi-lingual input for product name

* Fix LateError: LateInitializationError
  • Loading branch information
g123k authored Jan 26, 2025
1 parent d721a1c commit 4cef8f0
Show file tree
Hide file tree
Showing 22 changed files with 1,266 additions and 689 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ autocomplete:
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/simple_input_page.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/simple_input_page_helpers.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/simple_input_text_field.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/edit_product_image_viewer.dart'

✏️ Editing - Nutrition input:
- changed-files:
Expand All @@ -265,7 +266,6 @@ autocomplete:
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_availability_container.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_container_helper.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_facts_editor.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_image_viewer.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_serving_size.dart'
- any-glob-to-any-file: 'packages/smooth_app/lib/pages/product/nutrition_page/widgets/nutrition_serving_switch.dart'

Expand Down
20 changes: 12 additions & 8 deletions packages/smooth_app/lib/generic_lib/widgets/smooth_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class SmoothCardWithRoundedHeader extends StatelessWidget {
this.titleBackgroundColor,
this.contentBackgroundColor,
this.borderRadius,
this.includeShadow = true,
super.key,
});

Expand All @@ -133,20 +134,23 @@ class SmoothCardWithRoundedHeader extends StatelessWidget {
final Color? titleBackgroundColor;
final Color? contentBackgroundColor;
final BorderRadius? borderRadius;
final bool includeShadow;

@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: borderRadius ?? ROUNDED_BORDER_RADIUS,
boxShadow: const <BoxShadow>[
BoxShadow(
color: Color(0x03000000),
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0.0, 2.0),
),
],
boxShadow: includeShadow
? const <BoxShadow>[
BoxShadow(
color: Color(0x10000000),
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0.0, 2.0),
),
]
: null,
),
child: Column(
children: <Widget>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class SmoothTextFormField extends StatefulWidget {
this.spellCheckConfiguration,
this.allowEmojis = true,
this.maxLines,
this.borderRadius,
this.contentPadding,
});

final TextFieldTypes type;
Expand All @@ -51,6 +53,8 @@ class SmoothTextFormField extends StatefulWidget {
final SpellCheckConfiguration? spellCheckConfiguration;
final bool allowEmojis;
final int? maxLines;
final BorderRadius? borderRadius;
final EdgeInsetsGeometry? contentPadding;

@override
State<SmoothTextFormField> createState() => _SmoothTextFormFieldState();
Expand All @@ -76,7 +80,9 @@ class _SmoothTextFormFieldState extends State<SmoothTextFormField> {
Widget build(BuildContext context) {
final bool enableSuggestions = widget.type == TextFieldTypes.PLAIN_TEXT;
final bool autocorrect = widget.type == TextFieldTypes.PLAIN_TEXT;
final TextStyle textStyle = DefaultTextStyle.of(context).style;
final TextStyle textStyle = DefaultTextStyle.of(context).style.copyWith(
fontSize: 15.0,
);
final double textSize = textStyle.fontSize ?? 20.0;
final AppLocalizations appLocalization = AppLocalizations.of(context);

Expand Down Expand Up @@ -111,23 +117,25 @@ class _SmoothTextFormFieldState extends State<SmoothTextFormField> {
FilteringTextInputFormatter.deny(TextHelper.emojiRegex),
],
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: LARGE_SPACE,
vertical: SMALL_SPACE,
),
contentPadding: widget.contentPadding ??
const EdgeInsets.symmetric(
horizontal: LARGE_SPACE,
vertical: SMALL_SPACE,
),
isDense: widget.contentPadding != null,
prefixIcon: widget.prefixIcon,
filled: true,
hintStyle: (widget.hintTextStyle ?? const TextStyle()).apply(
overflow: TextOverflow.ellipsis,
),
hintText: widget.hintText,
hintMaxLines: widget.maxLines ?? 2,
border: const OutlineInputBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
border: OutlineInputBorder(
borderRadius: widget.borderRadius ?? CIRCULAR_BORDER_RADIUS,
),
enabledBorder: const OutlineInputBorder(
borderRadius: CIRCULAR_BORDER_RADIUS,
borderSide: BorderSide(
enabledBorder: OutlineInputBorder(
borderRadius: widget.borderRadius ?? CIRCULAR_BORDER_RADIUS,
borderSide: const BorderSide(
color: Colors.transparent,
width: 5.0,
),
Expand Down
35 changes: 35 additions & 0 deletions packages/smooth_app/lib/helpers/paint_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/rendering.dart';

class DashedLinePainter extends CustomPainter {
DashedLinePainter({
required Color color,
this.dashGap = 3.0,
this.dashSpace = 3.0,
}) : _paint = Paint()
..color = color
..strokeWidth = 1.0;

final double dashGap;
final double dashSpace;

final Paint _paint;

@override
void paint(Canvas canvas, Size size) {
double startX = 0.0;

while (startX < size.width) {
canvas.drawLine(
Offset(startX, 0),
Offset(startX + dashGap, 0),
_paint,
);

startX += dashGap + dashSpace;
}
}

@override
bool shouldRepaint(DashedLinePainter oldDelegate) =>
dashGap != oldDelegate.dashGap || dashSpace != oldDelegate.dashSpace;
}
13 changes: 13 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2516,8 +2516,21 @@
},
"basic_details": "Basic Details",
"product_name": "Product Name",
"product_names": "Product Names",
"add_basic_details_product_name_add_translation": "Add a new translation",
"add_basic_details_product_name_open_photo": "View front photo",
"add_basic_details_product_name_take_photo": "Take front photo",
"add_basic_details_product_name_error": "Please enter the product name",
"add_basic_details_product_name_hint": "Input the name of the product (eg: Nutella)",
"add_basic_details_product_name_other_translations": "{count,plural, one{{count} other translation} other{{count} other translations}}",
"@add_basic_details_product_name_other_translations": {
"description": "The number of other translations for a product name (count is always >= 1)",
"placeholders": {
"count": {
"type": "int"
}
}
},
"brand_name": "Brand name",
"brand_names": "Brand names",
"add_basic_details_brand_name_error": "Please enter the brand name",
Expand Down
8 changes: 4 additions & 4 deletions packages/smooth_app/lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@
}
}
},
"prices_button_count_proof": "{count,plural, one {}=0{Nessuna prova} =1{Una prova} other{{count} prove}}",
"prices_button_count_proof": "{count,plural, =0{Nessuna prova} =1{Una prova} other{{count} prove}}",
"@prices_button_count_proof": {
"description": "Number of proofs, for a button",
"placeholders": {
Expand All @@ -2218,7 +2218,7 @@
}
}
},
"prices_button_count_product": "{count,plural, one {}=0{Nessun prodotto} =1{Un prodotto} other{{count} prodotti}}",
"prices_button_count_product": "{count,plural, =0{Nessun prodotto} =1{Un prodotto} other{{count} prodotti}}",
"@prices_button_count_product": {
"description": "Number of products, for a button",
"placeholders": {
Expand All @@ -2227,7 +2227,7 @@
}
}
},
"prices_button_count_user": "{count,plural, one {}=0{Nessun utente} =1{Un utente} other{{count} utenti}}",
"prices_button_count_user": "{count,plural, =0{Nessun utente} =1{Un utente} other{{count} utenti}}",
"@prices_button_count_user": {
"description": "Number of users, for a button",
"placeholders": {
Expand All @@ -2236,7 +2236,7 @@
}
}
},
"prices_button_count_price": "{count,plural, one {}=0{Nessun prezzo} =1{Un prezzo} other{{count} prezzi}}",
"prices_button_count_price": "{count,plural, =0{Nessun prezzo} =1{Un prezzo} other{{count} prezzi}}",
"@prices_button_count_price": {
"description": "Number of prices, for a button",
"placeholders": {
Expand Down
22 changes: 11 additions & 11 deletions packages/smooth_app/lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@
"count": {}
}
},
"multiselect_title": "{count,plural, one {}=0{Geen geselecteerd product} =1{Eén geselecteerd product} other{{count} geselecteerde producten}}",
"multiselect_title": "{count,plural, =0{Geen geselecteerd product} =1{Eén geselecteerd product} other{{count} geselecteerde producten}}",
"@multiselect_title": {
"description": "Page title with the number of selected items",
"placeholders": {
Expand Down Expand Up @@ -2071,8 +2071,8 @@
"prices_app_dev_mode_flag": "Snelkoppeling naar de Prijzen-app op de productpagina",
"prices_app_button": "Ga naar de Prijzen-app",
"prices_generic_title": "Prijzen",
"prices_add_n_prices": "{count,plural, one {}=1{Voeg een prijs toe} other{Voeg {count} prijzen toe}}",
"prices_send_n_prices": "{count,plural, one {}=1{Verstuur 1 prijs} other{Verstuur {count} prijzen}}",
"prices_add_n_prices": "{count,plural, =1{Voeg een prijs toe} other{Voeg {count} prijzen toe}}",
"prices_send_n_prices": "{count,plural, =1{Verstuur 1 prijs} other{Verstuur {count} prijzen}}",
"prices_add_an_item": "Item toevoegen",
"prices_add_a_price": "Voeg een prijs toe",
"prices_add_a_receipt": "Een ontvangstbewijs toevoegen",
Expand Down Expand Up @@ -2100,7 +2100,7 @@
"prices_barcode_enter": "Voer de streepjescode in",
"prices_barcode_reader_action": "Streepjescodelezer",
"prices_view_prices": "Bekijk de prijzen",
"prices_product_accessibility_summary": "{count,plural, one {}=1{1 prijs} other{{count} prijzen}} voor {product}",
"prices_product_accessibility_summary": "{count,plural, =1{1 prijs} other{{count} prijzen}} voor {product}",
"@prices_product_accessibility_summary": {
"description": "A card summarizing the number of prices for a product",
"placeholders": {
Expand All @@ -2112,7 +2112,7 @@
}
}
},
"prices_list_length_one_page": "{count,plural, one {}=0{Nog geen prijs} =1{Slechts één prijs} other{Alle {count} prijzen}}",
"prices_list_length_one_page": "{count,plural, =0{Nog geen prijs} =1{Slechts één prijs} other{Alle {count} prijzen}}",
"@prices_list_length_one_page": {
"description": "Number of prices for one-page result",
"placeholders": {
Expand Down Expand Up @@ -2164,7 +2164,7 @@
"@prices_open_proof": {
"description": "Button to open a proof"
},
"prices_proofs_list_length_one_page": "{count,plural, one {}=0{Nog geen bewijs} =1{Slechts één bewijs} other{Alle {count} bewijzen}}",
"prices_proofs_list_length_one_page": "{count,plural, =0{Nog geen bewijs} =1{Slechts één bewijs} other{Alle {count} bewijzen}}",
"@prices_proofs_list_length_one_page": {
"description": "Number of proofs for one-page result",
"placeholders": {
Expand Down Expand Up @@ -2209,7 +2209,7 @@
}
}
},
"prices_button_count_proof": "{count,plural, one {}=0{Geen bewijs} =1{Eén bewijs} other{{count} bewijzen}}",
"prices_button_count_proof": "{count,plural, =0{Geen bewijs} =1{Eén bewijs} other{{count} bewijzen}}",
"@prices_button_count_proof": {
"description": "Number of proofs, for a button",
"placeholders": {
Expand All @@ -2218,7 +2218,7 @@
}
}
},
"prices_button_count_product": "{count,plural, one {}=0{Geen product} =1{Eén product} other{{count} producten}}",
"prices_button_count_product": "{count,plural, =0{Geen product} =1{Eén product} other{{count} producten}}",
"@prices_button_count_product": {
"description": "Number of products, for a button",
"placeholders": {
Expand All @@ -2227,7 +2227,7 @@
}
}
},
"prices_button_count_user": "{count,plural, one {}=0{Geen gebruiker} =1{Eén gebruiker} other{{count} gebruikers}}",
"prices_button_count_user": "{count,plural, =0{Geen gebruiker} =1{Eén gebruiker} other{{count} gebruikers}}",
"@prices_button_count_user": {
"description": "Number of users, for a button",
"placeholders": {
Expand All @@ -2236,7 +2236,7 @@
}
}
},
"prices_button_count_price": "{count,plural, one {}=0{Geen prijs} =1{Eén prijs} other{{count} prijzen}}",
"prices_button_count_price": "{count,plural, =0{Geen prijs} =1{Eén prijs} other{{count} prijzen}}",
"@prices_button_count_price": {
"description": "Number of prices, for a button",
"placeholders": {
Expand Down Expand Up @@ -3196,7 +3196,7 @@
"@download_top_products": {
"description": "Download the top 1000 products in your country for instant scanning"
},
"download_top_n_products": "Top {count,plural, one {}other{{count} producten}} downloaden in uw land voor direct scannen",
"download_top_n_products": "Top {count,plural, other{{count} producten}} downloaden in uw land voor direct scannen",
"@download_top_n_products": {
"placeholders": {
"count": {
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@
}
}
},
"prices_list_length_one_page": "{count,plural, one {}=0{Ainda sem preço} =1{Apenas um preço} other{Todos os {count} preços}}",
"prices_list_length_one_page": "{count,plural, =0{Ainda sem preço} =1{Apenas um preço} other{Todos os {count} preços}}",
"@prices_list_length_one_page": {
"description": "Number of prices for one-page result",
"placeholders": {
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/l10n/app_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@
"prices_app_button": "Перейдіть у додаток Ціни",
"prices_generic_title": "Ціни",
"prices_add_n_prices": "{count,plural, =1{Додайте ціну} other{Додайте {count} цін}}",
"prices_send_n_prices": "{count,plural, =1{Надіслати{count} ціну} few {Надіслати {count} ціни} many {Надіслати {count} цін}=1{Надіслати ціну} other{Надіслати {count} ціни}}",
"prices_send_n_prices": "{count,plural, =1{Надіслати{count} ціну} few {Надіслати {count} ціни} many {Надіслати {count} цін}other{Надіслати {count} ціни}}",
"prices_add_an_item": "Додати елемент",
"prices_add_a_price": "Додати ціну",
"prices_add_a_receipt": "Додати чек",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'dart:async';

import 'package:flutter/material.dart';

/// Wraps a TextEditingController and debounces its changes.
class DebouncedTextEditingController extends TextEditingController {
DebouncedTextEditingController({
TextEditingController? controller,
this.debounceTime = const Duration(milliseconds: 500),
}) {
replaceWith(controller ?? TextEditingController());
}

final Duration debounceTime;
TextEditingController? _controller;
Timer? _debounce;

void replaceWith(TextEditingController controller) {
_controller?.removeListener(_onWrappedTextEditingControllerChanged);
_controller = controller;
_controller?.addListener(_onWrappedTextEditingControllerChanged);
}

void _onWrappedTextEditingControllerChanged() {
if (_debounce?.isActive == true) {
_debounce!.cancel();
}

_debounce = Timer(
debounceTime,
() => super.notifyListeners(),
);
}

@override
set text(String newText) => _controller?.value = value;

@override
String get text => _controller?.text ?? '';

@override
TextEditingValue get value => _controller?.value ?? TextEditingValue.empty;

@override
set value(TextEditingValue newValue) => _controller?.value = newValue;

@override
void clear() => _controller?.clear();

@override
void dispose() {
_debounce?.cancel();
super.dispose();
}
}
Loading

0 comments on commit 4cef8f0

Please sign in to comment.