Flutter 使用Navigator.push(MaterialPageRoute)而不是AlertDialog
我想使用Navigator.push(MaterialPageRoute)而不是AlertDialog,因为现在我认为我的用户最好有一个完整的页面来发布内容,而不是一个对话框,我该如何编辑代码来做到这一点?提前谢谢Flutter 使用Navigator.push(MaterialPageRoute)而不是AlertDialog,flutter,dart,flutter-layout,flutter-appbar,Flutter,Dart,Flutter Layout,Flutter Appbar,我想使用Navigator.push(MaterialPageRoute)而不是AlertDialog,因为现在我认为我的用户最好有一个完整的页面来发布内容,而不是一个对话框,我该如何编辑代码来做到这一点?提前谢谢 appBar: AppBar( centerTitle: true, title: Text('hehe', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0),), actio
appBar: AppBar(
centerTitle: true,
title: Text('hehe',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0),),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: IconButton(icon: Icon(Icons.comment),
onPressed: () {
showDialog(context: context,
builder: (BuildContext context){
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
content: Form(key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
initialValue: '',
onSaved: (val) => board.subject = val,
validator: (val) => val == "" ? val: null,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.indigo,
child: Text(
'Post',
style: TextStyle(color: Colors.white),),
onPressed: () {
handleSubmit();
Navigator.of(context).pop();
},
),
)
],
),
),
);
},
);
}
),
),
],
),
appBar:appBar(
标题:对,
标题:文本(‘呵呵’,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:25.0),
行动:[
填充物(
填充:仅限常量边集(右:10.0),
子项:图标按钮(图标:图标(Icons.comment)),
已按下:(){
showDialog(上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框(
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(10.0)),
内容:表格(键:formKey,
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
填充物(
填充:边缘设置。全部(8.0),
子项:TextFormField(
初始值:“”,
onSaved:(val)=>board.subject=val,
验证程序:(val)=>val==“”?val:null,
),
),
填充物(
填充:边缘设置。全部(8.0),
孩子:升起按钮(
颜色:颜色,靛蓝,
子:文本(
"岗位",,
样式:TextStyle(颜色:Colors.white),),
已按下:(){
handleSubmit();
Navigator.of(context.pop();
},
),
)
],
),
),
);
},
);
}
),
),
],
),
创建一个StatefulWidget
子类sayMyForm
class MyForm extends StatefulWidget {
@override
_MyFormState createState() => _MyFormState();
}
class _MyFormState extends State<MyForm> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("My form")),
body: Form(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
initialValue: '',
onSaved: (val) => board.subject = val,
validator: (val) => val == "" ? val : null,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.indigo,
child: Text(
'Post',
style: TextStyle(color: Colors.white),
),
onPressed: () {
handleSubmit();
Navigator.of(context).pop();
},
),
)
],
),
),
);
}
}
因此,当单击按钮时,您将被导航到当前表单的新页面 创建一个
StatefulWidget
子类sayMyForm
class MyForm extends StatefulWidget {
@override
_MyFormState createState() => _MyFormState();
}
class _MyFormState extends State<MyForm> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("My form")),
body: Form(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
initialValue: '',
onSaved: (val) => board.subject = val,
validator: (val) => val == "" ? val : null,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.indigo,
child: Text(
'Post',
style: TextStyle(color: Colors.white),
),
onPressed: () {
handleSubmit();
Navigator.of(context).pop();
},
),
)
],
),
),
);
}
}
因此,当单击按钮时,您将被导航到当前表单的新页面 使用AlertDialog的内容创建一个新的StatefulWidget。通过这种方式,您可以使用Navigator移动到该页面。我迷路了,它当前处于有状态widgetyes中,但是如果您想使用Navigator.push,您需要移动到新的有状态Widget。。。这是实现全屏模式的方法。使用AlertDialog的内容创建一个新的StatefulWidget。通过这种方式,您可以使用Navigator移动到该页面。我迷路了,它当前处于有状态widgetyes中,但是如果您想使用Navigator.push,您需要移动到新的有状态Widget。。。这是实现全屏模式的方法。