在我执行函数showDialog 后键盘关闭。 但是,我希望键盘保持打开状态并且对话框位于键盘上方。
下面是我的代码。
附言:在this post它表明至少应该以某种方式与 Flutter 一起工作。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo Keyboard',
home: MyHomePage(title: 'Demo Keyboard'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(controller: controller),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// keyboard closes after I press on this button...
showDialog(
context: context,
child: AlertDialog(
content: SingleChildScrollView(
child: Text(
'How Would You Rate Our App?',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
最佳答案
请试试这个...
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo Keyboard',
home: MyHomePage(title: 'Demo Keyboard'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final controller = TextEditingController();
FocusNode _focusNode = FocusNode();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
focusNode: _focusNode,
controller: controller,
autofocus: true,),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// keyboard closes after I press on this button...
showDialog(
context: context,
child: AlertDialog(
content: SingleChildScrollView(
child: Text(
'How Would You Rate Our App?',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
https://stackoverflow.com/questions/59713730/
相关文章:
javascript - CSS 不透明度过渡不适用于 Safari
typescript - npm 如何发布 typescript 接口(interface)定义
excel - 查找工作表中的总行数和列数 - Microsoft Graph
android - 尝试在使用谷歌驱动器的 android 应用程序(使用 kotlin)webvi
java - Slf4j,logback - 从 json 中删除 mdc 标签
reactjs - 类型 'background' 上不存在属性 '{}' - React Rout
c# - 在 Blazor 应用程序中使用 Azure Active Directory 时如何在