Skip to content

[MacOS] TextField "onChanged" called three times when hitting backspace. #78629

Closed

Description

@TeddyLourson

Hi !
I'm currently building a RichTextField/RichTextEditor for Flutter, but I started having some bugs on MacOS that I don't have on other platforms (iOS, Web, Android). I wondered what it was and found out that the backspace key triggers the "onChanged" method multiple times on MacOS (might be the same on Windows or Linux, I don't have access to any of these OS to try, so I don't know).

Steps to Reproduce

  1. Run flutter create bug.
  2. In main.dart : inside the build method of _MyHomePageState, remove everything inside "body" and replace it with this :
TextField(
        onChanged: (text) => print('textChanged'),
      ),
  1. Run on macOS.
  2. Write some text (even a single letter would work).
  3. (Optional) Clear the log console.
  4. Press backspace once.

Expected results: "textChanged" logged 1x in the console.

Actual results: "textChanged" logged 3x in the console.

Activity

  1. LongCatIsLooong commented on Mar 21, 2021

    @LongCatIsLooong
    Contributor

    Not sure which commit fixed it, but it doesn't seem to be happening on the latest master branch. @Teio07 could you try out the latest master and see if that fixes the issue?

  2. TeddyLourson commented on Mar 21, 2021

    @TeddyLourson
    Author

    Amazing 👍 ! Just tried on the master branch and I confirm that it has been fixed. The problem is still there on the stable branch though.
    Thanks !

  3. TahaTesser commented on Mar 30, 2021

    @TahaTesser
    Contributor

    Hi @Teio07
    Thanks for filing the issue, I can still reproduce the issue on only stable, no issue on other channels

    code sample
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Material App',
          theme: ThemeData.dark(),
          home: Home(),
        );
      }
    }
    
    class Home extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Material App Bar'),
          ),
          body: Center(
            child: TextField(
              onChanged: (text) => print('textChanged'),
            ),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () {},
          ),
        );
      }
    }
    
    [   +2 ms] flutter: textChanged
    [        ] flutter: textChanged
    [ +699 ms] flutter: textChanged
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.0.3, on macOS 11.2.3 20D91 darwin-x64, locale
        en-GB)
        • Flutter version 2.0.3 at /Users/tahatesser/Code/flutter_stable
        • Framework revision 4d7946a68d (12 days ago), 2021-03-18 17:24:33 -0700
        • Engine revision 3459eb2436
        • Dart version 2.12.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Volumes/Extreme/SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = /Volumes/Extreme/SDK
        • Java binary at: /Applications/Android
          Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
        • Xcode 12.4, Build version 12D4e
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
    
    [✓] VS Code (version 1.54.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.20.0
    
    [✓] Connected device (3 available)
        • iPhone 12 (mobile) • 83060656-28E7-44CD-801E-B11EC3EC89BA • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
        • macOS (desktop)    • macos                                • darwin-x64
          • macOS 11.2.3 20D91 darwin-x64
        • Chrome (web)       • chrome                               • web-javascript
          • Google Chrome 89.0.4389.90
    
    • No issues found!

    Adding regression label because i think this wasn't by design

  4. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    c: regressionIt was better in the past than it is now
    and removed
    in triagePresently being triaged by the triage team
    on Mar 30, 2021
  5. justinmc commented on Apr 6, 2021

    @justinmc
    Contributor

    I'm going to close this since it seems to be fixed outside of stable. Feel free to comment and/or give a 👍 if this is still a problem for anyone.

  6. github-actions commented on Aug 3, 2021

    @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.

  7. locked as resolved and limited conversation to collaborators on Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsc: regressionIt was better in the past than it is nowfound in release: 2.0Found to occur in 2.0frameworkflutter/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/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions