Skip to content

Commit

Permalink
feat: Spellchecker on product name 5415 (#5451)
Browse files Browse the repository at this point in the history
* feat: added spell check configuration to the smooth text form

* feat: added spellcheck to product field in basic details page

* fix: fixed formatting
  • Loading branch information
jnnabugwu committed Jul 4, 2024
1 parent d2ac037 commit 1ff9a0a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SmoothTextFormField extends StatefulWidget {
this.onFieldSubmitted,
this.autofocus,
this.focusNode,
this.spellCheckConfiguration,
});

final TextFieldTypes type;
Expand All @@ -40,6 +41,7 @@ class SmoothTextFormField extends StatefulWidget {
final ValueChanged<String>? onFieldSubmitted;
final bool? autofocus;
final FocusNode? focusNode;
final SpellCheckConfiguration? spellCheckConfiguration;

@override
State<SmoothTextFormField> createState() => _SmoothTextFormFieldState();
Expand Down Expand Up @@ -83,6 +85,8 @@ class _SmoothTextFormFieldState extends State<SmoothTextFormField> {
setState(() {});
}
},
spellCheckConfiguration: widget.spellCheckConfiguration ??
const SpellCheckConfiguration.disabled(),
onFieldSubmitted: widget.onFieldSubmitted,
style: TextStyle(fontSize: textSize),
cursorHeight: textSize * (textStyle.height ?? 1.4),
Expand Down
84 changes: 60 additions & 24 deletions packages/smooth_app/lib/pages/product/add_basic_details_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -123,31 +128,62 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
),
),
SizedBox(height: _heightSpace),
if (_multilingualHelper.isMonolingual())
SmoothTextFormField(
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
)
else
Card(
child: Column(
children: <Widget>[
_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,
),
ConsumerFilter<UserPreferences>(
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,
spellCheckConfiguration: (prefs.getFlag(
UserPreferencesDevMode
.userPreferencesFlagSpellCheckerOnOcr) ??
false) &&
(Platform.isAndroid || Platform.isIOS)
? const SpellCheckConfiguration()
: const SpellCheckConfiguration.disabled(),
);
} else {
return Card(
child: Column(
children: <Widget>[
_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(),
),
),
],
),
],
),
),
);
}
},
),
SizedBox(height: _heightSpace),
LayoutBuilder(
builder: (
Expand Down

0 comments on commit 1ff9a0a

Please sign in to comment.