Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Spellchecker on product name 5415 #5451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading