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

[General]: FormBuilderTextField do not disabled validation when set AutovalidateMode.disabled and FormBuilder parent has autovalidateMode != AutovalidateMode.disabled #1461

Open
4 of 7 tasks
deandreamatias opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working originates from dependency The issue originates from package dependency

Comments

@deandreamatias
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

10.0.0-dev.1

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

Flutter doctor
[✓] 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
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<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _formKey = GlobalKey<FormBuilderState>();

  @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>[
              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 (flutter/flutter#107350 (comment))

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: flutter/flutter#125766

@deandreamatias deandreamatias added bug Something isn't working originates from dependency The issue originates from package dependency labels Jan 8, 2025
@deandreamatias deandreamatias changed the title [General]: [General]: FormBuilderTextField do not disabled validation when set AutovalidateMode.disabled and FormBuilder parent has autovalidateMode != AutovalidateMode.disabled Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working originates from dependency The issue originates from package dependency
Projects
None yet
Development

No branches or pull requests

1 participant