当我在Visual Studio中重新启动此代码时,autofocus
正在工作,键盘也在显示。当我关闭Visual Studio并在Android模拟器中重新打开应用程序时,键盘没有显示,但自动对焦正在工作(光标正在显示)。
但它的工作在android 5完美。
我的代码:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: TextField(
autofocus: true,
)
),
);
}
}
有人能修好吗?谢谢。
1条答案
按热度按时间mzmfm0qo1#
请尝试以下代码: