Correct enter clearing

This commit is contained in:
Hillel Coren 2021-02-07 11:01:20 +02:00
parent c0fc509691
commit c24bfbf778
5 changed files with 19 additions and 48 deletions

View File

@ -20,7 +20,6 @@ class DecoratedFormField extends StatelessWidget {
this.keyboardType, this.keyboardType,
this.minLines, this.minLines,
this.maxLines, this.maxLines,
this.textInputAction,
this.onFieldSubmitted, this.onFieldSubmitted,
this.initialValue, this.initialValue,
this.enabled = true, this.enabled = true,
@ -50,7 +49,6 @@ class DecoratedFormField extends StatelessWidget {
final bool obscureText; final bool obscureText;
final bool expands; final bool expands;
final bool autofocus; final bool autofocus;
final TextInputAction textInputAction;
final ValueChanged<String> onFieldSubmitted; final ValueChanged<String> onFieldSubmitted;
final ValueChanged<String> onChanged; final ValueChanged<String> onChanged;
final Icon suffixIcon; final Icon suffixIcon;
@ -65,14 +63,18 @@ class DecoratedFormField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget suffixIconButton; Widget suffixIconButton;
final hasValue = final hasValue =
(initialValue ?? '').isNotEmpty || (controller?.text ?? '').isNotEmpty; (initialValue ?? '').isNotEmpty || (controller?.text ?? '').isNotEmpty;
final enterShouldSubmit =
kIsWeb && isDesktop(context) && onSavePressed != null;
if (hasValue && key == null) { if (hasValue && key == null) {
if (suffixIcon == null && enabled) { if (suffixIcon == null && enabled) {
suffixIconButton = IconButton( suffixIconButton = IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () => //onPressed: () => controller != null ? controller.text = '' : onChanged(''),
controller != null ? controller.text = '' : onChanged(''), onPressed: () => null,
); );
} }
} }
@ -124,17 +126,18 @@ class DecoratedFormField extends StatelessWidget {
autocorrect: isMoney || isPercent ? false : autocorrect, autocorrect: isMoney || isPercent ? false : autocorrect,
obscureText: obscureText, obscureText: obscureText,
initialValue: initialValue, initialValue: initialValue,
textInputAction: textInputAction ?? textInputAction: keyboardType == TextInputType.multiline
(keyboardType == TextInputType.multiline ? TextInputAction.newline
? TextInputAction.newline : enterShouldSubmit
: TextInputAction.next), ? TextInputAction.done
: TextInputAction.next,
onChanged: onChanged, onChanged: onChanged,
onFieldSubmitted: (value) { onFieldSubmitted: (value) {
if (onFieldSubmitted != null) { if (onFieldSubmitted != null) {
return onFieldSubmitted(value); return onFieldSubmitted(value);
} else if (keyboardType == TextInputType.multiline) { } else if (keyboardType == TextInputType.multiline) {
return null; return null;
} else if (kIsWeb && isDesktop(context) && onSavePressed != null) { } else if (enterShouldSubmit) {
onSavePressed(context); onSavePressed(context);
} }
}, },

View File

@ -5,14 +5,12 @@ import 'package:invoiceninja_flutter/utils/localization.dart';
class PasswordFormField extends StatefulWidget { class PasswordFormField extends StatefulWidget {
const PasswordFormField({ const PasswordFormField({
this.controller, this.controller,
this.textInputAction,
this.autoValidate, this.autoValidate,
this.newPassword = true, this.newPassword = true,
this.labelText, this.labelText,
}); });
final TextEditingController controller; final TextEditingController controller;
final TextInputAction textInputAction;
final bool autoValidate; final bool autoValidate;
final bool newPassword; final bool newPassword;
final String labelText; final String labelText;
@ -36,7 +34,6 @@ class _PasswordFormFieldState extends State<PasswordFormField> {
return DecoratedFormField( return DecoratedFormField(
controller: widget.controller, controller: widget.controller,
textInputAction: widget.textInputAction,
autocorrect: false, autocorrect: false,
autovalidate: widget.autoValidate, autovalidate: widget.autoValidate,
decoration: InputDecoration( decoration: InputDecoration(

View File

@ -401,10 +401,6 @@ class _LoginState extends State<LoginView> {
DecoratedFormField( DecoratedFormField(
controller: _emailController, controller: _emailController,
autocorrect: false, autocorrect: false,
textInputAction:
_isFormComplete && !_createAccount
? TextInputAction.done
: TextInputAction.next,
label: localization.email, label: localization.email,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
autovalidate: _autoValidate, autovalidate: _autoValidate,
@ -418,10 +414,6 @@ class _LoginState extends State<LoginView> {
if (_emailLogin && !_recoverPassword) if (_emailLogin && !_recoverPassword)
PasswordFormField( PasswordFormField(
controller: _passwordController, controller: _passwordController,
textInputAction:
_isFormComplete && !_createAccount
? TextInputAction.done
: TextInputAction.next,
autoValidate: _autoValidate, autoValidate: _autoValidate,
newPassword: _createAccount, newPassword: _createAccount,
), ),
@ -429,9 +421,6 @@ class _LoginState extends State<LoginView> {
DecoratedFormField( DecoratedFormField(
controller: _urlController, controller: _urlController,
autocorrect: false, autocorrect: false,
textInputAction: _isFormComplete
? TextInputAction.done
: TextInputAction.next,
label: localization.url, label: localization.url,
validator: (val) => validator: (val) =>
val.isEmpty || val.trim().isEmpty val.isEmpty || val.trim().isEmpty
@ -444,7 +433,6 @@ class _LoginState extends State<LoginView> {
labelText: labelText:
'${localization.secret} (${localization.optional})', '${localization.secret} (${localization.optional})',
controller: _secretController, controller: _secretController,
textInputAction: TextInputAction.done,
autoValidate: _autoValidate, autoValidate: _autoValidate,
), ),
if (_createAccount) if (_createAccount)

View File

@ -251,32 +251,27 @@ class _CompanyDetailsState extends State<CompanyDetails>
? localization.pleaseEnterAName ? localization.pleaseEnterAName
: null, : null,
autovalidate: autoValidate, autovalidate: autoValidate,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => _focusNode.nextFocus(), onFieldSubmitted: (String value) => _focusNode.nextFocus(),
), ),
DecoratedFormField( DecoratedFormField(
label: localization.idNumber, label: localization.idNumber,
controller: _idNumberController, controller: _idNumberController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => _focusNode.nextFocus(), onFieldSubmitted: (String value) => _focusNode.nextFocus(),
), ),
DecoratedFormField( DecoratedFormField(
label: localization.vatNumber, label: localization.vatNumber,
controller: _vatNumberController, controller: _vatNumberController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => _focusNode.nextFocus(), onFieldSubmitted: (String value) => _focusNode.nextFocus(),
), ),
DecoratedFormField( DecoratedFormField(
label: localization.website, label: localization.website,
controller: _websiteController, controller: _websiteController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => _focusNode.nextFocus(), onFieldSubmitted: (String value) => _focusNode.nextFocus(),
), ),
DecoratedFormField( DecoratedFormField(
label: localization.email, label: localization.email,
controller: _emailController, controller: _emailController,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => _focusNode.nextFocus(), onFieldSubmitted: (String value) => _focusNode.nextFocus(),
), ),
DecoratedFormField( DecoratedFormField(
@ -352,7 +347,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
DecoratedFormField( DecoratedFormField(
label: localization.address1, label: localization.address1,
controller: _address1Controller, controller: _address1Controller,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => onFieldSubmitted: (String value) =>
_focusNode.nextFocus(), _focusNode.nextFocus(),
autofillHints: [AutofillHints.streetAddressLine1], autofillHints: [AutofillHints.streetAddressLine1],
@ -360,7 +354,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
DecoratedFormField( DecoratedFormField(
label: localization.address2, label: localization.address2,
controller: _address2Controller, controller: _address2Controller,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => onFieldSubmitted: (String value) =>
_focusNode.nextFocus(), _focusNode.nextFocus(),
autofillHints: [AutofillHints.streetAddressLine2], autofillHints: [AutofillHints.streetAddressLine2],
@ -368,7 +361,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
DecoratedFormField( DecoratedFormField(
label: localization.city, label: localization.city,
controller: _cityController, controller: _cityController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => onFieldSubmitted: (String value) =>
_focusNode.nextFocus(), _focusNode.nextFocus(),
autofillHints: [AutofillHints.addressCity], autofillHints: [AutofillHints.addressCity],
@ -376,7 +368,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
DecoratedFormField( DecoratedFormField(
label: localization.state, label: localization.state,
controller: _stateController, controller: _stateController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => onFieldSubmitted: (String value) =>
_focusNode.nextFocus(), _focusNode.nextFocus(),
autofillHints: [AutofillHints.addressState], autofillHints: [AutofillHints.addressState],
@ -384,7 +375,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
DecoratedFormField( DecoratedFormField(
label: localization.postalCode, label: localization.postalCode,
controller: _postalCodeController, controller: _postalCodeController,
textInputAction: TextInputAction.next,
onFieldSubmitted: (String value) => onFieldSubmitted: (String value) =>
_focusNode.nextFocus(), _focusNode.nextFocus(),
autofillHints: [AutofillHints.postalCode], autofillHints: [AutofillHints.postalCode],

View File

@ -63,7 +63,7 @@ packages:
name: build_daemon name: build_daemon
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.6" version: "2.1.7"
build_resolvers: build_resolvers:
dependency: transitive dependency: transitive
description: description:
@ -442,7 +442,7 @@ packages:
name: flutter_styled_toast name: flutter_styled_toast
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.4.0+1" version: "1.5.0+1"
flutter_test: flutter_test:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -593,13 +593,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.1" version: "3.1.1"
json_rpc_2:
dependency: transitive
description:
name: json_rpc_2
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.2"
local_auth: local_auth:
dependency: "direct main" dependency: "direct main"
description: description:
@ -767,14 +760,14 @@ packages:
name: permission_handler name: permission_handler
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.0.1+1" version: "5.1.0+2"
permission_handler_platform_interface: permission_handler_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: permission_handler_platform_interface name: permission_handler_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.2"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -921,7 +914,7 @@ packages:
name: shared_preferences_windows name: shared_preferences_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.2+2" version: "0.0.2+3"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -989,7 +982,7 @@ packages:
name: sqflite name: sqflite
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.2+2" version: "1.3.2+3"
sqflite_common: sqflite_common:
dependency: transitive dependency: transitive
description: description:
@ -1178,7 +1171,7 @@ packages:
name: web_socket_channel name: web_socket_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0"
webdriver: webdriver:
dependency: transitive dependency: transitive
description: description: