Skip to content

TextField, TextInputAction.unspecified and events #28252

@andyduke

Description

@andyduke

TextField triggers the onEditingComplete and onSubmitted events differently when textInputAction = TextInputAction.unspecified.

When pressing the enter button on the keyboard, in the the debug-build on the emulator, both events are fired, in the release-build on the Android 6.x device, both events are not fired.

Reproduce code

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Keyboard Test',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: TestPage(),
    );
  }
}

class TestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.all(20),
        alignment: Alignment.center,
        child: TextField(
          decoration: InputDecoration(
            hintText: 'Input',
          ),
          textInputAction: TextInputAction.unspecified,
          onEditingComplete: () => alert(context, 'Editing Complete'),
          onSubmitted: (_) => alert(context, 'Submitted', 25),
        ),
      ),
    );
  }

  // This code is not related to the problem, it is only needed to show the message on the screen.
  void alert(BuildContext context, String text, [double offset = 0]) {
    OverlayEntry overlay;
    overlay = OverlayEntry(
      opaque: false,
      builder: (BuildContext context) {
        return Positioned(
          top: 30 + offset, left: 20, right: 20,
          child: GestureDetector(
            child: Material(
              type: MaterialType.transparency,
              child: Container(
                padding: const EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(3.0),
                  boxShadow: [BoxShadow(color: Colors.black38, blurRadius: 10.0, offset: Offset(0, 1))],
                ),
                alignment: Alignment.center,
                child: Text(text),
              ),
            ),
            onTap: () {
              overlay.remove();
            },
          ),
        );
      }
    );

    Future.microtask(() {
      Overlay.of(context).insert(overlay);
    });
  }

}

How it should be (this is how it works in debug on the emulator)

After pressing this key on the keyboard
key

A message should appear at the top
flutter_03

Flutter doctor

Tested on stable version 1.0.0 and on dev version 1.2.1, the result is the same.

[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 6.1.7601], locale ru-RU)
    • Flutter version 1.0.0 at D:\.Flutter\flutter
    • Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at D:\.Flutter\android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = D:\.Flutter\android-sdk
    • Java binary at: D:\.Flutter\jdk\bin\java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
    • All Android licenses accepted.

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).

[√] Connected device (1 available)
    • Custom • 192.168.20.101:5555 • android-x86 • Android 6.0 (API 23)

! Doctor found issues in 1 category.
[√] Flutter (Channel dev, v1.2.1, on Microsoft Windows [Version 6.1.7601], locale ru-RU)
    • Flutter version 1.2.1 at D:\.Flutter\flutter-beta
    • Framework revision 8661d8aecd (6 days ago), 2019-02-14 19:19:53 -0800
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at D:\.Flutter\android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = D:\.Flutter\android-sdk
    • ANDROID_SDK_ROOT = D:\.Flutter\android-sdk
    • Java binary at: D:\.Flutter\jdk\bin\java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
    • All Android licenses accepted.

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).

[√] Connected device (1 available)
    • Custom • 192.168.20.101:5555 • android-x86 • Android 6.0 (API 23)

! Doctor found issues in 1 category.

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.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions