flutter-form-builder-ecosystem / flutter-form-builder-ecosystem/flutter_form_builder
[General]: FormBuilderTextField do not disabled validation when set AutovalidateMode.disabled and FormBuilder parent has autovalidateMode != AutovalidateMode.disabled
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 561
- PR merge metrics
- No merged PRs in 30d
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Package/Plugin version
10.0.0-dev.1
### Platforms
- [X] Android
- [ ] iOS
- [X] Linux
- [ ] MacOS
- [X] Web
- [ ] Windows
### Flutter doctor
Flutter doctor
```bash
[✓] Flutter (Channel stable, 3.27.1, on Ubuntu 24.04.1 LTS 6.8.0-51-generic, locale en_US.UTF-8)
• Flutter version 3.27.1 on channel stable at /home/matias/fvm/versions/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 17025dd882 (3 weeks ago), 2024-12-17 03:23:09 +0900
• Engine revision cb4b5fff73
• Dart version 3.6.0
• DevTools version 2.40.2
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
• Android SDK at /home/matias/Android/Sdk
• Platform android-35, build-tools 35.0.0-rc4
• Java binary at: /home/matias/.local/share/JetBrains/Toolbox/apps/android-studio/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /usr/bin/google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 18.1.3 (1ubuntu1)
• cmake version 3.28.3
• ninja version 1.11.1
• pkg-config version 1.8.1
[✓] Android Studio (version 2024.1)
• Android Studio at /home/matias/.local/share/JetBrains/Toolbox/apps/android-studio
• Flutter plugin version 81.0.2
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
[✓] VS Code (version 1.96.2)
• VS Code at /snap/code/current/usr/share/code
• Flutter extension version 3.102.0
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 24.04.1 LTS 6.8.0-51-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.177
[✓] Network resources
• All expected network resources are available.
• No issues found!
```
### Minimal code example
Code sample
```dart
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.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 createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
final _formKey = GlobalKey();
@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: [
FormBuilder(
key: _formKey,
autovalidateMode: AutovalidateMode.always,
child: FormBuilderTextField(
name: 'text',
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),
),
);
}
}
```
### Current Behavior
When parent widget `FormBuilder` has property autovalidateMode with `AutovalidateMode.always` or `AutovalidateMode.onUserInteraction` and `FormBuilderTextField` has the property autovalidateMode with value `AutovalidateMode.disabled`; the `FormBuilderTextField` validate after the first user validation, like `AutovalidateMode.onUserInteraction`
### Expected Behavior
When `FormBuilderTextField` 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 parent widget `FormBuilder`
This would be follow the Flutter's inherited widget convention were the innermost takes priority (https://github.com/flutter/flutter/issues/107350#issuecomment-1295694555)
### Steps To Reproduce
1. Run code sample
2. Write text into `FormBuilderTextField`
3. Error: Show error even autovalidateMode on `FormBuilderTextField` is disabled
### Aditional information
Waiting for solving this on Flutter SDK: https://github.com/flutter/flutter/issues/125766
Contributor guide
Assessment
This issue has not been assessed yet.