Skip to content

Unable get focus of TextFormField - keyboard disappears #31827

@calvinmuller

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)

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.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