Skip to content

[iOS][iPad]: Tapping on textfield couple of times stops opening the system keyboard. #101067

Open
@martin-labanic

Description

@martin-labanic

Encountered what appears to be a focus bug on iOS devices where a TextFormField will stop responding.

Steps to Reproduce

  1. Execute flutter run on the example project targetting a iOS device (simulator will NOT work).
  2. Once loaded, start tapping in various places in the text field.
  3. Keep tapping until the keyboard is no longer showing and the textfield cannot be interacted with.

Expected results: A text field that retains focus and can be interacted with.

Actual results: A text field that has lost focus and can no longer be interacted with in any capacity.

Sample Code

https://github.com/martin-labanic/flutter_focus_bug

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _form_key = GlobalKey<FormState>();

  void unfocusWidgets(BuildContext context) {
    FocusScope.of(context).unfocus();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text('Focus Bug'),
      ),

      body: Listener( // Used to dismiss the keyboard if the user taps elsewhere on the screen.
        onPointerDown: (event) {
          unfocusWidgets(context);
        },
        child: SafeArea(
          child: SizedBox.expand(
            child: Container(
              color: Colors.white,
              padding: const EdgeInsets.all(10.0),
              child: Align(
                alignment: Alignment.topCenter,
                child: Form(
                  key: _form_key,
                  child: TextFormField(
                    initialValue: 'On iOS, tap this text field in various places. Eventually the keyboard will no longer show up and interacting with this widget will not work.',
                    keyboardType: TextInputType.text,
                    autofocus: false,
                    maxLines: 3,
                    onChanged: (value) { },
                  ),
                ),
              )
            )
          ),
        ),
      ),
    );
  }
}

Logs

flutter run --verbose

flutter_run_verbose.log

flutter analyze
Analyzing focus_bug...                                                  

   info • Name non-constant identifiers using lowerCamelCase • lib/main.dart:51:9 • non_constant_identifier_names

flutter doctor -v
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3 21E230 darwin-x64, locale en-CA)
    • Flutter version 2.10.4 at /Users/tt/Library/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (6 days ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/tt/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.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 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.64.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Mike’s iPad (mobile) • cba0debb2f88ef7bd67604d84601a01da040dfd0 • ios            • iOS 15.3.1 19D52
    • Chrome (web)         • chrome                                   • web-javascript • Google Chrome 99.0.4844.84

[✓] HTTP Host Availability
    • All required HTTP hosts are available

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 problemse: device-specificOnly manifests on certain devicesengineflutter/engine repository. See also e: labels.found in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions