Skip to content

[Form] AutovalidateMode.onUserInteraction validates Textfields without interaction #107350

@newtaDev

Description

@newtaDev

Steps to Reproduce

Execute flutter run on the code sample

Expected results:

Screen.Recording.2022-07-09.at.9.42.26.PM.mov

Actual results:

Screen.Recording.2022-07-09.at.9.38.12.PM.mov
Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: 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({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(20),
          child: Column(
            children: [
              const Text('has issue onUserInteraction (wraped with Form)'),
              Form(
                key: _formKey,
                autovalidateMode: AutovalidateMode.onUserInteraction,
                child: Column(
                  children: [
                    TextFormField(
                      decoration: const InputDecoration(
                        hintText: 'Enter your Name',
                      ),
                      validator: (val) {
                        return val!.length < 4 ? 'Not valid' : null;
                      },
                    ),
                    const SizedBox(height: 20),
                    TextFormField(
                      decoration: const InputDecoration(
                        hintText: 'Enter your email Id',
                      ),
                      validator: (val) {
                        return val!.length < 4 ? 'email not valid' : null;
                      },
                    ),
                    const SizedBox(height: 20),
                    TextFormField(
                      decoration: const InputDecoration(
                        hintText: 'Enter your password',
                      ),
                      obscureText: true,
                      validator: (val) {
                        return val!.length < 4 ? 'password not valid' : null;
                      },
                    ),
                  ],
                ),
              ),
              const SizedBox(height: 40),
              const Text('Working fine onUserInteraction (wraped without Form)'),
              TextFormField(
                decoration: const InputDecoration(
                  hintText: 'Enter your Name',
                ),
                autovalidateMode: AutovalidateMode.onUserInteraction,
                validator: (val) {
                  return val!.length < 4 ? 'Not valid' : null;
                },
              ),
              const SizedBox(height: 20),
              TextFormField(
                decoration: const InputDecoration(
                  hintText: 'Enter your email Id',
                ),
                autovalidateMode: AutovalidateMode.onUserInteraction,
                validator: (val) {
                  return val!.length < 4 ? 'email not valid' : null;
                },
              ),
              const SizedBox(height: 20),
              TextFormField(
                decoration: const InputDecoration(
                  hintText: 'Enter your password',
                ),
                autovalidateMode: AutovalidateMode.onUserInteraction,
                obscureText: true,
                validator: (val) {
                  return val!.length < 4 ? 'password not valid' : null;
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Logs
[✓] Flutter (Channel stable, 3.0.2, on macOS
    12.4 21F79 darwin-arm, locale en-IN)
    • Flutter version 3.0.2 at
      /Users/newton/Development/flutter
    • Upstream repository
      https://github.com/flutter/flutter.git
    • Framework revision cd41fdd495 (4 weeks
      ago), 2022-06-08 09:52:13 -0700
    • Engine revision f15f824b57
    • Dart version 2.17.3
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android
    devices (Android SDK version 32.0.0-rc1)
    • Android SDK at
      /Users/newton/Library/Android/sdk
    • Platform android-32, build-tools
      32.0.0-rc1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bi
      n/java
    • Java version OpenJDK Runtime Environment
      (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode
    13.4.1)
    • Xcode at
      /Applications/Xcode.app/Contents/Develop
      er
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google
      Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨
      https://plugins.jetbrains.com/plugin/921
      2-flutter
    • Dart plugin can be installed from:
      🔨
      https://plugins.jetbrains.com/plugin/635
      1-dart
    • Java version OpenJDK Runtime Environment
      (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.68.1)
    • VS Code at /Applications/Visual Studio
      Code.app/Contents
    • Flutter extension version 3.42.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) •
      emulator-5554 • android-arm64  • Android
      12 (API 31) (emulator)
    • macOS (desktop)             • macos
      • darwin-arm64   • macOS 12.4 21F79
      darwin-arm
    • Chrome (web)                • chrome
      • web-javascript • Google Chrome
      103.0.5060.53

[✓] HTTP Host Availability
    • All required HTTP hosts are available

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.found in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish linehas reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions