简体   繁体   中英

Using Flutter, how can I trigger onSubmitted() of TextField on iOS?

Please take a look at the following Flutter code snippet: it creates a TextField that is intended as a single line input field tat will submit its value when Return is pressed:

child: new TextField(
  decoration: _deco,
  maxLines: 1,
  autofocus: true,
  onSubmitted: (newValue) {print(newValue);},
  onChanged: (newValue) {
    setState(() {
      strTemperature = newValue.trim();
    });
  })),

On the iOS Simulator the corresponding app looks as follows:

我的示例应用程序的屏幕截图

As you can see the widget is configured with maxLines = 1 , but when I click the Return key on the onscreen keyboard, line feeds are insert. Please spot the narrow blue cursor a couple of lines below the widget. Also, I see no console output, which should be the case because of my onSubmitted() lambda.

Am I configuring the text field correctly, or am I missing something?

This looks to me like it's actually just a bug in the iOS version of Flutter. Filed issue #9839 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM