Skip to content

Unable get focus of TextFormField - keyboard disappears #31827

Closed

Description

@calvinmuller

Steps to Reproduce

Run this sample, click the body button "Tab 1" - the route will appear modally, you will see the keyboard attempt to show - then disappear.

You are then unable to get focus of any textfield, this never used to be an issue in my app until I upgraded flutter yesterday.

import 'package:flutter/cupertino.dart';
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: 'Flutter Demo',
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.message)),
          BottomNavigationBarItem(icon: Icon(Icons.block)),
        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        switch (index) {
          case 0:
            return CupertinoTabView(
              builder: (context) => Page1(
                    title: "Tab 1",
                  ),
            );
            break;
          case 1:
            return CupertinoTabView(
              builder: (context) => Page1(
                    title: "Tab 2",
                  ),
            );
            break;
        }
      },
    );
  }
}

class Page1 extends StatelessWidget {
  final String title;

  const Page1({Key key, this.title}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: FlatButton(
          child: Text(title),
          onPressed: () {
            Navigator.of(context, rootNavigator: true).push(
              MaterialPageRoute(
                fullscreenDialog: true,
                builder: (context) => CreateEditProductWizardPage(),
              ),
            );
          },
        ),
      ),
    );
  }
}

class CreateEditProductWizardPage extends StatefulWidget {
  final bool editing;

  const CreateEditProductWizardPage({Key key, this.editing = false})
      : super(key: key);

  @override
  _CreateEditProductWizardPageState createState() =>
      _CreateEditProductWizardPageState();
}

class _CreateEditProductWizardPageState
    extends State<CreateEditProductWizardPage> {
  static final _formKey = GlobalKey<FormState>();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Form(
        key: _formKey,
        child: ListView(
          children: [
            TextFormField(
              autofocus: true,
              maxLines: 1,
            ),
            Divider(
              height: 0,
            ),
            TextFormField(
              maxLines: 2,
            ),
            Divider(
              height: 0,
            ),
            TextFormField(
              textInputAction: TextInputAction.done,
              keyboardType: TextInputType.number,
            ),
            Divider(
              height: 0,
            ),
            TextFormField(
              textInputAction: TextInputAction.done,
              keyboardType: TextInputType.number,
            ),
          ],
        ),
      ),
    );
  }
}

Logs

Nothing produced in the logs

[✓] Flutter (Channel master, v1.5.9-pre.66, on Mac OS X 10.14.4 18E226, locale en-ZA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
[✓] Android Studio (version 3.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2018.3.2)
[✓] Connected device (1 available)

Activity

  1. calvinmuller commented on Apr 30, 2019

    @calvinmuller
    Author

    switching to flutter stable channel I can't reproduce this, so it's definitely been introduced recently.

  2. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: cupertino_uicupertino_ui package in flutter/packages
    and removed
    a: text inputEntering text in a text field or keyboard related problems
    on Apr 30, 2019
  3. HansMuller commented on Apr 30, 2019

    @HansMuller
    Contributor
  4. gspencergoog commented on Apr 30, 2019

    @gspencergoog
    Contributor

    Thank you for the clear reproduction case!

    I was able to easily reproduce this, and I believe I have a fix. I'll put together a PR shortly.

  5. self-assigned this
    on Apr 30, 2019
  6. calvinmuller commented on May 1, 2019

    @calvinmuller
    Author

    Thanks!

  7. hgokulchavan commented on Apr 14, 2021

    @hgokulchavan

    I am having same issue. Seems like it is broken once again since Flutter 2.0. Please resolve this.

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

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

Labels

c: regressionIt was better in the past than it is nowframeworkflutter/packages/flutter repository. See also f: labels.p: 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