Skip to content

The engine notify twice for the same value when use numeric keyboard input #65811

Closed

Description

@xu-baolin

@justinmc Hi,
This is the track for #65754 (comment)

Step to reproduce

There are some differences between the real device and the simulator, but both of them will repeatedly notify the same value.

Real device, OPPO, Reno3, Sogou input.

1, Run the app, focus the textField, switch to numeric keyboard, input any number will trigger.

I/flutter (30312): updateEditingValue [TextEditingValue(text: ┤I love flutter!1├, selection: TextSelection(baseOffset: 16, extentOffset: 16, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]
I/flutter (30312): Second text field: I love flutter!1
I/flutter (30312): updateEditingValue [TextEditingValue(text: ┤I love flutter!1├, selection: TextSelection(baseOffset: 16, extentOffset: 16, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]
I/flutter (30312): updateEditingValue [TextEditingValue(text: ┤I love flutter!12├, selection: TextSelection(baseOffset: 17, extentOffset: 17, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]
I/flutter (30312): Second text field: I love flutter!12
I/flutter (30312): updateEditingValue [TextEditingValue(text: ┤I love flutter!12├, selection: TextSelection(baseOffset: 17, extentOffset: 17, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]

Simulator, Chinese language.

1, Run the app, clean the textField, switch to numeric keyboard, input one number
2, Delete the number will trigger the issue
20200915_110514

I/flutter (17052): updateEditingValue [TextEditingValue(text: ┤├, selection: TextSelection(baseOffset: 0, extentOffset: 0, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]
I/flutter (17052): Second text field: 
I/flutter (17052): updateEditingValue [TextEditingValue(text: ┤├, selection: TextSelection(baseOffset: 0, extentOffset: 0, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))]

Sample Code

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Retrieve Text Input',
      home: MyCustomForm(),
    );
  }
}

// Define a custom Form widget.
class MyCustomForm extends StatefulWidget {
  @override
  _MyCustomFormState createState() => _MyCustomFormState();
}

// Define a corresponding State class.
// This class holds data related to the Form.
class _MyCustomFormState extends State<MyCustomForm> {
  // Create a text controller and use it to retrieve the current value
  // of the TextField.
  final myController = TextEditingController(text: 'I love flutter!');
  final newController = TextEditingController(text: 'I am a new controller.');
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = myController;

    _controller.addListener(_printLatestValue);
  }

  @override
  void dispose() {
    // Clean up the controller when the widget is removed from the widget tree.
    // This also removes the _printLatestValue listener.
    myController.dispose();
    newController.dispose();
    super.dispose();
  }

  _printLatestValue() {
    print("Second text field: ${myController.text}");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Retrieve Text Input'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: <Widget>[
//            TextField(
//              onChanged: (text) {
//                print("First text field: $text");
//              },
//            ),
            TextField(
              controller: _controller,
              keyboardType: TextInputType.multiline,
              maxLines: 7,
//              inputFormatters: [LengthLimitingTextInputFormatter(3)],
            ),
            MaterialButton(
                child: Text("set to '123'"),
                onPressed: () {
                  setState(() {
                    _controller.value = TextEditingValue(
                        text: '123',
                        composing:TextRange(start: -1, end: -1),
                        selection: TextSelection(
                            baseOffset: 3,
                            extentOffset: 3,
                            affinity: TextAffinity.downstream,
                            isDirectional: false));
                  });
                }),
            MaterialButton(
                child: Text("set to '12'"),
                onPressed: () {
                  setState(() {
                    _controller.text = '12';
                  });
                }),
            MaterialButton(
                child: Text('change controller'),
                onPressed: () {
                  setState(() {
                    _controller = newController;
                  });
                }),
          ],
        ),
      ),
    );
  }
}

Activity

  1. TahaTesser commented on Sep 15, 2020

    @TahaTesser
    Contributor

    Hi @xu-baolin
    I am unable to print updateEditingValue using your code sample, does this require more than just your code sample?

  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 15, 2020
  3. xu-baolin commented on Sep 15, 2020

    @xu-baolin
    MemberAuthor

    you should add log in function 'updateEditingValue'.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 15, 2020
  5. TahaTesser commented on Sep 15, 2020

    @TahaTesser
    Contributor
    logs
    Launching lib/main.dart on RMX2001 in debug mode...
    ✓ Built build/app/outputs/flutter-apk/app-debug.apk.
    Connecting to VM Service at ws://127.0.0.1:55064/sE2wrh_Rc4M=/ws
    I/GED     ( 4438): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 27, oppidx_max 27, oppidx_min 0
    W/ClipData( 4438): Failure opening stream
    W/ClipData( 4438): java.lang.SecurityException: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{c98bb89 4438:com.example.master_flutter/u0a299} (pid=4438, uid=10299) that is not exported from UID 10171
    W/ClipData( 4438): 	at android.os.Parcel.createException(Parcel.java:2087)
    W/ClipData( 4438): 	at android.os.Parcel.readException(Parcel.java:2055)
    W/ClipData( 4438): 	at android.os.Parcel.readException(Parcel.java:2003)
    W/ClipData( 4438): 	at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5370)
    W/ClipData( 4438): 	at android.app.ActivityThread.acquireProvider(ActivityThread.java:6967)
    W/ClipData( 4438): 	at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2849)
    W/ClipData( 4438): 	at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2255)
    W/ClipData( 4438): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1688)
    W/ClipData( 4438): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1642)
    W/ClipData( 4438): 	at android.content.ClipData$Item.coerceToText(ClipData.java:364)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:287)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:24)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:82)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141)
    W/ClipData( 4438): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
    W/ClipData( 4438): 	at android.os.MessageQueue.nativePollOnce(Native Method)
    W/ClipData( 4438): 	at android.os.MessageQueue.next(MessageQueue.java:336)
    W/ClipData( 4438): 	at android.os.Looper.loop(Looper.java:182)
    W/ClipData( 4438): 	at android.app.ActivityThread.main(ActivityThread.java:7822)
    W/ClipData( 4438): 	at java.lang.reflect.Method.invoke(Native Method)
    W/ClipData( 4438): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    W/ClipData( 4438): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
    W/ClipData( 4438): Caused by: android.os.RemoteException: Remote stack trace:
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:7639)
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:8026)
    W/ClipData( 4438): 	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2212)
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3067)
    W/ClipData( 4438): 	at com.android.server.am.OppoActivityManagerService.onTransact(OppoActivityManagerService.java:99)
    W/ClipData( 4438):
    I/.master_flutte( 4438): ProcessProfilingInfo new_methods=469 is saved saved_to_disk=1 resolve_classes_delay=5000
    D/ColorViewRootUtil( 4438): nav bar mode ignore false downX 644 downY 381 mScreenHeight 2400 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 0 rotation 0 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=644.0, y[0]=381.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=493534223, downTime=493534223, deviceId=3, source=0x1002, displayId=0 }
    I/flutter ( 4438): Second text field: I love flutter!
    I/Choreographer( 4438): Skipped 4 frames!  The application may be doing too much work on its main thread.
    W/IInputConnectionWrapper( 4438): getTextBeforeCursor on inactive InputConnection
    I/flutter ( 4438): TextEditingValue(text: ┤I love flutter!├, selection: TextSelection(baseOffset: 15, extentOffset: 15, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
    W/IInputConnectionWrapper( 4438): getSelectedText on inactive InputConnection
    I/flutter ( 4438): Second text field: I love flutter!
    W/IInputConnectionWrapper( 4438): getTextAfterCursor on inactive InputConnection
    W/IInputConnectionWrapper( 4438): beginBatchEdit on inactive InputConnection
    W/IInputConnectionWrapper( 4438): endBatchEdit on inactive InputConnection
    W/ClipData( 4438): Failure opening stream
    W/ClipData( 4438): java.lang.SecurityException: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{c98bb89 4438:com.example.master_flutter/u0a299} (pid=4438, uid=10299) that is not exported from UID 10171
    W/ClipData( 4438): 	at android.os.Parcel.createException(Parcel.java:2087)
    W/ClipData( 4438): 	at android.os.Parcel.readException(Parcel.java:2055)
    W/ClipData( 4438): 	at android.os.Parcel.readException(Parcel.java:2003)
    W/ClipData( 4438): 	at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5370)
    W/ClipData( 4438): 	at android.app.ActivityThread.acquireProvider(ActivityThread.java:6967)
    W/ClipData( 4438): 	at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2849)
    W/ClipData( 4438): 	at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2255)
    W/ClipData( 4438): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1688)
    W/ClipData( 4438): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1642)
    W/ClipData( 4438): 	at android.content.ClipData$Item.coerceToText(ClipData.java:364)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:287)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:24)
    W/ClipData( 4438): 	at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:82)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141)
    W/ClipData( 4438): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
    W/ClipData( 4438): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
    W/ClipData( 4438): 	at android.os.MessageQueue.nativePollOnce(Native Method)
    W/ClipData( 4438): 	at android.os.MessageQueue.next(MessageQueue.java:336)
    W/ClipData( 4438): 	at android.os.Looper.loop(Looper.java:182)
    W/ClipData( 4438): 	at android.app.ActivityThread.main(ActivityThread.java:7822)
    W/ClipData( 4438): 	at java.lang.reflect.Method.invoke(Native Method)
    W/ClipData( 4438): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    W/ClipData( 4438): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
    W/ClipData( 4438): Caused by: android.os.RemoteException: Remote stack trace:
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:7639)
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:8026)
    W/ClipData( 4438): 	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2212)
    W/ClipData( 4438): 	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3067)
    W/ClipData( 4438): 	at com.android.server.am.OppoActivityManagerService.onTransact(OppoActivityManagerService.java:99)
    W/ClipData( 4438):
    W/IInputConnectionWrapper( 4438): getTextBeforeCursor on inactive InputConnection
    W/IInputConnectionWrapper( 4438): getSelectedText on inactive InputConnection
    W/IInputConnectionWrapper( 4438): getTextAfterCursor on inactive InputConnection
    I/flutter ( 4438): TextEditingValue(text: ┤I love flutter!├, selection: TextSelection(baseOffset: 15, extentOffset: 15, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
    I/flutter ( 4438): TextEditingValue(text: ┤I love flutter!2├, selection: TextSelection(baseOffset: 16, extentOffset: 16, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
    I/flutter ( 4438): Second text field: I love flutter!2
    I/flutter ( 4438): TextEditingValue(text: ┤I love flutter!23├, selection: TextSelection(baseOffset: 17, extentOffset: 17, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
    I/flutter ( 4438): Second text field: I love flutter!23
    I/flutter ( 4438): TextEditingValue(text: ┤I love flutter!23├, selection: TextSelection(baseOffset: 17, extentOffset: 17, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
    W/IInputConnectionWrapper( 4438): getTextBeforeCursor on inactive InputConnection
    W/IInputConnectionWrapper( 4438): getSelectedText on inactive InputConnection
    W/IInputConnectionWrapper( 4438): getTextAfterCursor on inactive InputConnection
    W/IInputConnectionWrapper( 4438): beginBatchEdit on inactive InputConnection
    W/IInputConnectionWrapper( 4438): getTextBeforeCursor on inactive InputConnection
    W/IInputConnectionWrapper( 4438): endBatchEdit on inactive InputConnection
    D/SurfaceView( 4438): updateScreenMode w:1080 h:2268 ViewRoot w:1080 h:2400
    D/SurfaceView( 4438): try to resquest 60Hz
    I/GED     ( 4438): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 27, oppidx_max 27, oppidx_min 0
    I/SurfaceView( 4438): 30673836 visibleChanged:true -> SurfaceHolder.Callback.surfaceDestroyed
    D/Surface ( 4438): Surface::disconnect(this=0x7685fe3000,api=1)
    D/ViewRootImpl( 4438): setSurfaceViewCreated, created:false
    D/Surface ( 4438): Surface::disconnect(this=0x7685fe3000,api=-1)
    D/SurfaceView( 4438): updateScreenMode w:0 h:0 ViewRoot w:1080 h:2400
    D/SurfaceView( 4438): try to resquest 90Hz
    D/ViewRootImpl( 4438): set screen refresh mode 0 due to SurfaceView-30673836
    I/Choreographer( 4438): Skipped 13 frames!  The application may be doing too much work on its main thread.
    D/Surface ( 4438): Surface::disconnect(this=0x7685fe1000,api=1)
    V/PhoneWindow( 4438): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@1d091b9, this = DecorView@8d6e4b2[MainActivity]
    
    
    code sample
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Retrieve Text Input',
          home: MyCustomForm(),
        );
      }
    }
    
    // Define a custom Form widget.
    class MyCustomForm extends StatefulWidget {
      @override
      _MyCustomFormState createState() => _MyCustomFormState();
    }
    
    // Define a corresponding State class.
    // This class holds data related to the Form.
    class _MyCustomFormState extends State<MyCustomForm> {
      // Create a text controller and use it to retrieve the current value
      // of the TextField.
      final myController = TextEditingController(text: 'I love flutter!');
      final newController = TextEditingController(text: 'I am a new controller.');
      TextEditingController _controller;
    
      @override
      void initState() {
        super.initState();
        _controller = myController;
    
        _controller.addListener(_printLatestValue);
      }
    
      @override
      void dispose() {
        // Clean up the controller when the widget is removed from the widget tree.
        // This also removes the _printLatestValue listener.
        myController.dispose();
        newController.dispose();
        super.dispose();
      }
    
      _printLatestValue() {
        print("Second text field: ${myController.text}");
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Retrieve Text Input'),
          ),
          body: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              children: <Widget>[
    //            TextField(
    //              onChanged: (text) {
    //                print("First text field: $text");
    //              },
    //            ),
                TextField(
                  controller: _controller,
                  keyboardType: TextInputType.multiline,
                  maxLines: 7,
    //              inputFormatters: [LengthLimitingTextInputFormatter(3)],
                ),
                MaterialButton(
                    child: Text("set to '123'"),
                    onPressed: () {
                      setState(() {
                        _controller.value = TextEditingValue(
                            text: '123',
                            composing: TextRange(start: -1, end: -1),
                            selection: TextSelection(
                                baseOffset: 3,
                                extentOffset: 3,
                                affinity: TextAffinity.downstream,
                                isDirectional: false));
                      });
                    }),
                MaterialButton(
                    child: Text("set to '12'"),
                    onPressed: () {
                      setState(() {
                        _controller.text = '12';
                      });
                    }),
                MaterialButton(
                    child: Text('change controller'),
                    onPressed: () {
                      setState(() {
                        _controller = newController;
                      });
                    }),
              ],
            ),
          ),
        );
      }
    }
    
    
    flutter doctor -v
    [✓] Flutter (Channel master, 1.22.0-10.0.pre.176, on Mac OS X 10.15.6 19G2021, locale en-GB)
        • Flutter version 1.22.0-10.0.pre.176 at /Users/tahatesser/Code/flutter_master
        • Framework revision 96ca0e272b (3 hours ago), 2020-09-15 09:02:04 +0100
        • Engine revision 7e962ba911
        • Dart version 2.10.0 (build 2.10.0-124.0.dev)
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/tahatesser/Code/sdk
        • Platform android-30, build-tools 30.0.2
        • ANDROID_HOME = /Users/tahatesser/Code/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-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.7)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.7, Build version 11E801a
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 49.0.2
        • Dart plugin version 193.7547
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] VS Code (version 1.49.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.14.1
    
    [✓] Connected device (4 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 10 (API 29)
        • macOS (desktop)  • macos            • darwin-x64     • Mac OS X 10.15.6 19G2021
        • Web Server (web) • web-server       • web-javascript • Flutter Tools
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 85.0.4183.102
    
    • No issues found!
  6. added
    a: text inputEntering text in a text field or keyboard related problems
    engineflutter/engine related. See also e: labels.
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Sep 15, 2020
  7. goderbauer commented on Sep 16, 2020

    @goderbauer
    Member
  8. added
    P2Important issues not at the top of the work list
    on Dec 11, 2020
  9. maheshj01 commented on Jan 10, 2023

    @maheshj01
    Member

    Hi @xu-baolin, I verified the issue on stable and the master channel with Pinyin input on Xiaomi Redmi k20 pro with Gboard and I am unable to reproduce the issue. I believe this issue is fixed.

    Screen.Recording.2023-01-09.at.11.03.51.PM.mov
    code sample
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          title: 'Retrieve Text Input',
          home: MyCustomForm(),
        );
      }
    }
    
    // Define a custom Form widget.
    class MyCustomForm extends StatefulWidget {
      const MyCustomForm({super.key});
    
      @override
      _MyCustomFormState createState() => _MyCustomFormState();
    }
    
    // Define a corresponding State class.
    // This class holds data related to the Form.
    class _MyCustomFormState extends State<MyCustomForm> {
      // Create a text controller and use it to retrieve the current value
      // of the TextField.
      final myController = TextEditingController(text: 'I love flutter!');
      final newController = TextEditingController(text: 'I am a new controller.');
      late TextEditingController _controller;
    
      @override
      void initState() {
        super.initState();
        _controller = myController;
    
        _controller.addListener(_printLatestValue);
      }
    
      @override
      void dispose() {
        // Clean up the controller when the widget is removed from the widget tree.
        // This also removes the _printLatestValue listener.
        myController.dispose();
        newController.dispose();
        super.dispose();
      }
    
      _printLatestValue() {
        print("Second text field: ${myController.text}");
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Retrieve Text Input'),
          ),
          body: GestureDetector(
            onTap: () => FocusScope.of(context).unfocus(),
            child: Column(
              children: <Widget>[
    //            TextField(
    //              onChanged: (text) {
    //                print("First text field: $text");
    //              },
    //            ),
                TextField(
                  controller: _controller,
                  keyboardType: TextInputType.multiline,
                  maxLines: 7,
    //              inputFormatters: [LengthLimitingTextInputFormatter(3)],
                ),
                MaterialButton(
                    child: const Text("set to '123'"),
                    onPressed: () {
                      setState(() {
                        _controller.value = const TextEditingValue(
                            text: '123',
                            composing: TextRange(start: -1, end: -1),
                            selection: TextSelection(
                                baseOffset: 3,
                                extentOffset: 3,
                                affinity: TextAffinity.downstream,
                                isDirectional: false));
                      });
                    }),
                MaterialButton(
                    child: const Text("set to '12'"),
                    onPressed: () {
                      setState(() {
                        _controller.text = '12';
                      });
                    }),
                MaterialButton(
                    child: const Text('change controller'),
                    onPressed: () {
                      setState(() {
                        _controller = newController;
                      });
                    }),
              ],
            ),
          ),
        );
      }
    }
    
    flutter doctor -v (mac)
    [✓] Flutter (Channel master, 3.7.0-13.0.pre.131, on macOS 13.1 22C65 darwin-arm64, locale en-IN)
        • Flutter version 3.7.0-13.0.pre.131 on channel master at /Users/mahesh/Development/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 0196e6050b (2 days ago), 2022-12-31 11:10:23 -0500
        • Engine revision 932591ec04
        • Dart version 3.0.0 (build 3.0.0-76.0.dev)
        • DevTools version 2.20.0
        • 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 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/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 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] 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/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.74.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.56.0
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 108.0.5359.124
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
        
    • No issues found!
    
    [✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-IN)
        • Flutter version 3.3.9 on channel stable at /Users/mahesh/Development/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b8f7f1f986 (24 hours ago), 2022-11-23 06:43:51 +0900
        • Engine revision 8f2221fbef
        • Dart version 2.18.5
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/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 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] 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/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.70.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.53.20221101
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    

    Closing as fixed. Incase you still encounter the issue then please feel free to write in the comments and we will reopen it.

  10. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 10, 2023
  11. github-actions commented on Mar 4, 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.

  12. locked as resolved and limited conversation to collaborators on Mar 4, 2023
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

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.found in release: 1.22Found to occur in 1.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions