Skip to content

When the Form widget calls the reset method, if it contains widget of the FormField type (such as TextFormField), the onChange method of those components will not be called #123009

Closed

Description

@yeleibo
class TestWidget extends StatelessWidget {
  final _formKey = GlobalKey<FormState>();
  TestWidget({Key? key}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: Column(
        children: [
          ElevatedButton(
            onPressed: (){
              _formKey.currentState?.reset();
            },
            child: const Text("reset")
          ),
          TextFormField(
            onChanged: (value) {
              // not executed on _formKey.currentState?.reset()
              print(value);
            }
          )
        ],
      )
    );
  }
}

Activity

  1. darshankawar commented on Mar 21, 2023

    @darshankawar
    Member

    @yeleibo
    Can you provide flutter doctor -v alongwith current vs expected behavior upon running code sample above ?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 21, 2023
  3. yeleibo commented on Mar 21, 2023

    @yeleibo
    Author

    @darshankawar

    flutter doctor -v ``` [√] Flutter (Channel stable, 3.7.5, on Microsoft Windows [版本 10.0.19045.2728], locale zh-CN) • Flutter version 3.7.5 on channel stable at C:\soft\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision c07f788 (4 weeks ago), 2023-02-22 17:52:33 -0600 • Engine revision 0f359063c4 • Dart version 2.19.2 • DevTools version 2.20.1
    [X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)
    
    [!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
        • Android SDK at C:\soft\Sdk
        • Platform android-33-ext4, build-tools 33.0.2
        • ANDROID_HOME = C:\soft\Sdk
        • Java binary at: D:\soft\Java\jdk-11\bin\java
        • Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
        ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Enterprise 2022 17.4.5)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Enterprise
        • Visual Studio Enterprise 2022 version 17.4.33403.182
        • Windows 10 SDK version 10.0.22000.0
    
    [!] Android Studio (version 2022.1)
        • Android Studio at C:\soft\Android\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
        X Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [√] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [版本 10.0.19045.2728]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 111.0.5563.65
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 111.0.1661.44
    
    </details>
    
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 21, 2023
  5. darshankawar commented on Mar 22, 2023

    @darshankawar
    Member

    @yeleibo
    On which platform are you seeing the behavior ? I ran your code sample using latest master on iOS and observed as shown in below video which seem to work fine ?

    123009.mov
    runnable code sample
    
    import 'package:flutter/material.dart';
    import 'dart:async';
    
    final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
    
    void main() {
      runApp(MaterialApp(
        home: TestWidget(),
      ));
    }
    
    class TestWidget extends StatelessWidget {
      final _formKey = GlobalKey<FormState>();
      TestWidget({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Form(
                key: _formKey,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ElevatedButton(
                        onPressed: (){
                          _formKey.currentState?.reset();
                        },
                        child: const Text("reset")
                    ),
                    TextFormField(
                        onChanged: (value) {
                          // not executed on _formKey.currentState?.reset()
                          print(value);
                        }
                    )
                  ],
                )
            ),
          )
        );
      }
    }
    
    
  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 22, 2023
  7. yeleibo commented on Mar 22, 2023

    @yeleibo
    Author

    @darshankawar
    You should notice that when you click the reset button, the component's onChange method is not executed. When you enter normally, the onChange method is executed normally. Solution I have created a pull request

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 22, 2023
  9. darshankawar commented on Mar 23, 2023

    @darshankawar
    Member

    Thanks for the update.

    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.7.7, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.7.7 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2ad6cd72c0 (12 days ago), 2023-03-08 09:41:59 -0800
        • Engine revision 1837b5be5f
        • Dart version 2.19.4
        • DevTools version 2.20.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.9.0-12.0.pre.18, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.9.0-12.0.pre.18 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 28f17d345b (39 minutes ago), 2023-03-20 21:08:41 -0700
        • Engine revision ea6ed14b4e
        • Dart version 3.0.0 (build 3.0.0-345.0.dev)
        • DevTools version 2.22.2
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/dhs/Library/Android/sdk
        ✗ cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/macos#android-setup for
          more details.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA.app
        • Flutter plugin version 65.1.4
        • Dart plugin version 213.7228
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 15.3.1 19D52
        • macOS (desktop)           • macos                                    •
          darwin-x64     • macOS 12.2.1 21D62 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 109.0.5414.119
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
          
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    
  10. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Mar 23, 2023
  11. 3 remaining items

  12. self-assigned this
    on Sep 6, 2023
  13. moved this from To do to In progress in Nevercodeon Sep 6, 2023
  14. moved this from In progress to PR submitted in Nevercodeon Sep 12, 2023
  15. moved this from PR submitted to Done (PR merged) in Nevercodeon Sep 21, 2023
  16. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 21, 2023
  17. github-actions commented on Oct 5, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: text inputEntering text in a text field or keyboard related problemsfound in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions