From 2edaa9f666d2604efe979085a77ea162d498ad2d Mon Sep 17 00:00:00 2001 From: Jordan Nnabugwu Date: Sat, 22 Jun 2024 18:50:10 -0400 Subject: [PATCH 1/3] feat: added spell check configuration to the smooth text form --- .../lib/generic_lib/widgets/smooth_text_form_field.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart index 8ea02fadb2a..61d53d70d43 100644 --- a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart +++ b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart @@ -64,6 +64,7 @@ class _SmoothTextFormFieldState extends State { final AppLocalizations appLocalization = AppLocalizations.of(context); return TextFormField( + spellCheckConfiguration: const SpellCheckConfiguration(), keyboardType: widget.textInputType, controller: widget.controller, enabled: widget.enabled, From 79aa02656ef7bf574635e3be987b92a574f05061 Mon Sep 17 00:00:00 2001 From: Jordan Nnabugwu Date: Sun, 30 Jun 2024 20:51:55 -0400 Subject: [PATCH 2/3] feat: added spellcheck to product field in basic details page --- .../widgets/smooth_text_form_field.dart | 4 +- .../pages/product/add_basic_details_page.dart | 46 ++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart index 61d53d70d43..346a6f66840 100644 --- a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart +++ b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart @@ -24,6 +24,7 @@ class SmoothTextFormField extends StatefulWidget { this.onFieldSubmitted, this.autofocus, this.focusNode, + this.spellCheckConfiguration, }); final TextFieldTypes type; @@ -40,6 +41,7 @@ class SmoothTextFormField extends StatefulWidget { final ValueChanged? onFieldSubmitted; final bool? autofocus; final FocusNode? focusNode; + final SpellCheckConfiguration? spellCheckConfiguration; @override State createState() => _SmoothTextFormFieldState(); @@ -64,7 +66,6 @@ class _SmoothTextFormFieldState extends State { final AppLocalizations appLocalization = AppLocalizations.of(context); return TextFormField( - spellCheckConfiguration: const SpellCheckConfiguration(), keyboardType: widget.textInputType, controller: widget.controller, enabled: widget.enabled, @@ -84,6 +85,7 @@ class _SmoothTextFormFieldState extends State { setState(() {}); } }, + spellCheckConfiguration: widget.spellCheckConfiguration ?? const SpellCheckConfiguration.disabled(), onFieldSubmitted: widget.onFieldSubmitted, style: TextStyle(fontSize: textSize), cursorHeight: textSize * (textStyle.height ?? 1.4), diff --git a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart index b6e272b3e48..e09f3e7658b 100644 --- a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart +++ b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart @@ -1,14 +1,19 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/background/background_task_details.dart'; import 'package:smooth_app/cards/product_cards/product_image_carousel.dart'; +import 'package:smooth_app/data_models/preferences/user_preferences.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/generic_lib/widgets/smooth_text_form_field.dart'; import 'package:smooth_app/helpers/analytics_helper.dart'; import 'package:smooth_app/helpers/product_cards_helper.dart'; +import 'package:smooth_app/helpers/provider_helper.dart'; import 'package:smooth_app/pages/input/smooth_autocomplete_text_field.dart'; import 'package:smooth_app/pages/input/unfocus_field_when_tap_outside.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart'; import 'package:smooth_app/pages/product/common/product_buttons.dart'; import 'package:smooth_app/pages/product/common/product_refresher.dart'; import 'package:smooth_app/pages/product/may_exit_page_helper.dart'; @@ -123,14 +128,31 @@ class _AddBasicDetailsPageState extends State { ), ), SizedBox(height: _heightSpace), - if (_multilingualHelper.isMonolingual()) - SmoothTextFormField( + ConsumerFilter( + buildWhen: ( + UserPreferences? previousValue, + UserPreferences currentValue, + ) { + return previousValue?.getFlag(UserPreferencesDevMode.userPreferencesFlagSpellCheckerOnOcr) != + currentValue.getFlag(UserPreferencesDevMode.userPreferencesFlagSpellCheckerOnOcr); + }, + builder: (BuildContext context, UserPreferences prefs, Widget? child) { + if (_multilingualHelper.isMonolingual()){ + return SmoothTextFormField( controller: _productNameController, type: TextFieldTypes.PLAIN_TEXT, hintText: appLocalizations.product_name, - ) - else - Card( + spellCheckConfiguration: (prefs.getFlag( + UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr) ?? + false) && + (Platform.isAndroid || Platform.isIOS) + ? const SpellCheckConfiguration() + : const SpellCheckConfiguration.disabled(), + ); + } + else { + return Card( child: Column( children: [ _multilingualHelper.getLanguageSelector( @@ -143,11 +165,21 @@ class _AddBasicDetailsPageState extends State { controller: _productNameController, type: TextFieldTypes.PLAIN_TEXT, hintText: appLocalizations.product_name, - ), + spellCheckConfiguration: (prefs.getFlag( + UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr) ?? + false) && + (Platform.isAndroid || Platform.isIOS) + ? const SpellCheckConfiguration() + : const SpellCheckConfiguration.disabled(), + ), ), ], ), - ), + ); + } + }, + ), SizedBox(height: _heightSpace), LayoutBuilder( builder: ( From ff87ede795167288b46838d5ad07dc61716aaa42 Mon Sep 17 00:00:00 2001 From: Jordan Nnabugwu Date: Mon, 1 Jul 2024 19:23:25 -0400 Subject: [PATCH 3/3] fix: fixed formatting --- .../widgets/smooth_text_form_field.dart | 3 +- .../pages/product/add_basic_details_page.dart | 92 ++++++++++--------- 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart index 346a6f66840..ce4d0fc6166 100644 --- a/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart +++ b/packages/smooth_app/lib/generic_lib/widgets/smooth_text_form_field.dart @@ -85,7 +85,8 @@ class _SmoothTextFormFieldState extends State { setState(() {}); } }, - spellCheckConfiguration: widget.spellCheckConfiguration ?? const SpellCheckConfiguration.disabled(), + spellCheckConfiguration: widget.spellCheckConfiguration ?? + const SpellCheckConfiguration.disabled(), onFieldSubmitted: widget.onFieldSubmitted, style: TextStyle(fontSize: textSize), cursorHeight: textSize * (textStyle.height ?? 1.4), diff --git a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart index e09f3e7658b..c59d5fdd03d 100644 --- a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart +++ b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart @@ -133,52 +133,56 @@ class _AddBasicDetailsPageState extends State { UserPreferences? previousValue, UserPreferences currentValue, ) { - return previousValue?.getFlag(UserPreferencesDevMode.userPreferencesFlagSpellCheckerOnOcr) != - currentValue.getFlag(UserPreferencesDevMode.userPreferencesFlagSpellCheckerOnOcr); + return previousValue?.getFlag(UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr) != + currentValue.getFlag(UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr); }, - builder: (BuildContext context, UserPreferences prefs, Widget? child) { - if (_multilingualHelper.isMonolingual()){ - return SmoothTextFormField( - controller: _productNameController, - type: TextFieldTypes.PLAIN_TEXT, - hintText: appLocalizations.product_name, - spellCheckConfiguration: (prefs.getFlag( - UserPreferencesDevMode - .userPreferencesFlagSpellCheckerOnOcr) ?? - false) && - (Platform.isAndroid || Platform.isIOS) - ? const SpellCheckConfiguration() - : const SpellCheckConfiguration.disabled(), - ); - } - else { - return Card( - child: Column( - children: [ - _multilingualHelper.getLanguageSelector( - setState: setState, - product: _product, + builder: (BuildContext context, UserPreferences prefs, + Widget? child) { + if (_multilingualHelper.isMonolingual()) { + return SmoothTextFormField( + controller: _productNameController, + type: TextFieldTypes.PLAIN_TEXT, + hintText: appLocalizations.product_name, + spellCheckConfiguration: (prefs.getFlag( + UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr) ?? + false) && + (Platform.isAndroid || Platform.isIOS) + ? const SpellCheckConfiguration() + : const SpellCheckConfiguration.disabled(), + ); + } else { + return Card( + child: Column( + children: [ + _multilingualHelper.getLanguageSelector( + setState: setState, + product: _product, + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: SmoothTextFormField( + controller: _productNameController, + type: TextFieldTypes.PLAIN_TEXT, + hintText: appLocalizations.product_name, + spellCheckConfiguration: (prefs.getFlag( + UserPreferencesDevMode + .userPreferencesFlagSpellCheckerOnOcr) ?? + false) && + (Platform.isAndroid || + Platform.isIOS) + ? const SpellCheckConfiguration() + : const SpellCheckConfiguration + .disabled(), + ), + ), + ], ), - Padding( - padding: const EdgeInsets.all(8.0), - child: SmoothTextFormField( - controller: _productNameController, - type: TextFieldTypes.PLAIN_TEXT, - hintText: appLocalizations.product_name, - spellCheckConfiguration: (prefs.getFlag( - UserPreferencesDevMode - .userPreferencesFlagSpellCheckerOnOcr) ?? - false) && - (Platform.isAndroid || Platform.isIOS) - ? const SpellCheckConfiguration() - : const SpellCheckConfiguration.disabled(), - ), - ), - ], - ), - ); - } - }, + ); + } + }, ), SizedBox(height: _heightSpace), LayoutBuilder(