-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Run code sample
- Write text into
TextFormField - Error: Show error even
autovalidateModeon TextFormField is disabled
Expected results
When TextFormField has the property autovalidateMode with value AutovalidateMode.disabled, the field won't show the error, event with property autovalidateMode with AutovalidateMode.always or AutovalidateMode.onUserInteraction on Form parent widget
This would be follow the Flutter's inherited widget convention were the innermost takes priority (#107350 (comment))
Actual results
When Form parent widget has property autovalidateMode with AutovalidateMode.always or AutovalidateMode.onUserInteraction and TextFormField has the property autovalidateMode with value AutovalidateMode.disabled; the TextFormField validate after the first user validation, like AutovalidateMode.onUserInteraction
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Form(
autovalidateMode: AutovalidateMode.always,
child: TextFormField(
autovalidateMode: AutovalidateMode.disabled,
validator: (value) =>
value == null || value.length < 4 ? 'Not valid' : null,
),
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _formKey.currentState!.validate(),
tooltip: 'Validate',
child: const Icon(Icons.check),
),
);
}
}Screenshots or Video
Screenshots / Video demonstration
FORM-ISSUE.webm
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.7.12, on Ubuntu 22.04.2 LTS 5.19.0-41-generic, locale en_US.UTF-8)
• Flutter version 3.7.12 on channel stable at /home/matias/develop/flutter/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (12 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/matias/Android/Sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /snap/bin/firefox
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 14.0.0-1ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2021.3)
• Android Studio at /snap/android-studio/125/android-studio
• Flutter plugin version 72.1.1
• Dart plugin version 213.7433
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] Android Studio
• Android Studio at /snap/android-studio/current/android-studio
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /snap/android-studio/current/android-studio
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.2 LTS 5.19.0-41-generic
• Chrome (web) • chrome • web-javascript • Mozilla Firefox 112.0.1
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!Additional information
- Maybe related with [Form]
AutovalidateMode.onUserInteractionvalidates Textfields without interaction #107350 and the linked PR fix: FormAutovalidateMode.onUserInteractionbehavior #120730 - I think that this error is because if not set
autovalidateModeor set AutovalidateMode.disabled, is the same behavior. Can see in this line}) : autovalidateMode = autovalidateMode ?? AutovalidateMode.disabled; - With currently behavior and definition, if by default
autovalidateModeon FormField is disabled, theautovalidateModeproperty onFormparent never would be works becauseFormFieldproperty has priority with respect toForm
deandreamatias, mdeandrea-mrmilu, ikicodedev and yuta-mizumotoyuta-mizumoto
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team