For some reason, I cannot focus on a TextField after on the next page after navigating. The keyboard would automatically dismiss when the TextField is selected. If I set autofocus: true
on the TextField, then the keyboard will infinitely popup and immediately dismiss over and over again.
I encountered this when my app was a reasonable size but I was able to recreate this in a minimal example app.
I am using Dart 2.0.0-dev.55.0 with Flutter beta v0.3.2.
Code for main page:
import 'package:flutter/material.dart';
import 'settings.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Helpful text.',),
// ===== Where navigation happens =====
RaisedButton(
onPressed: () {
Navigator.push(context, PageRouteBuilder(
pageBuilder: (_, __, ___) => SettingsPage()));
},
child: Text('Go to input page'),
),
],
),
),
);
}
}
Here is the code for the page with the TextField.
import 'package:flutter/material.dart';
class SettingsPage extends StatefulWidget {
SettingsPage({Key key}) :
super(key: key);
@override
_SettingsPage createState() => new _SettingsPage();
}
class _SettingsPage extends State<SettingsPage> {
@override
Widget build(BuildContext context) {
final key = GlobalKey<ScaffoldState>();
return Scaffold(
key: key,
backgroundColor: Colors.white,
appBar: AppBar(
title: Text("Settings"),
),
body: ListView(
children: <Widget>[
Text("Enter something"),
// Can't focus on this widget
TextField(),
],
),
);
}
}
I can focus fine on TextField on the main page if I put one there, but can't on the one in the Settings page. I assume it has something to do with the keyboard not taking priority over the popped up page? Or what is going on? How I can get the app to just focus on input fields on a navigated page?
ListView
. Can you try to move it out. I run into this recently myself. I assume it's a bug, but might be missing knowledge on my side as well. github.com/flutter/flutter/issues/10498 – Circularbody: TextField(),
in the Settings page and I still cannot focus on it. Same thing happens if I changeListView
into aColumn
. I'm going to look more into the issue you linked but so far looks like the bug is still is alive sadly. – Confined