使用 appBar 图标打开表单
Use an appBar icon to open a form
.
我想在我的 appBar 中使用一个图标来打开我的表单。目前我的表单位于我的应用程序主体(列)中。我怎样才能做到这一点,而不是在正文中使用表单,我可以点击图标,然后会出现一个弹出窗口,有点像写推文?
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Social App'),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: IconButton(icon: Icon(Icons.add), onPressed: (){})
),
],
),
body: Column(
children: <Widget>[
Flexible(
flex: 0,
child: Card(
child: Form(
key: formKey,
child: Flex(
direction: Axis.vertical,
children: <Widget>[
ListTile(
leading: Icon(Icons.subject),
title: TextFormField(
initialValue: '',
onSaved: (val) => board.subject = val,
validator: (val) => val == "" ? val: null,
),
),
ListTile(
leading: Icon(Icons.message),
title: TextFormField(
initialValue: '',
onSaved: (val) => board.body = val,
validator: (val) => val == "" ? val: null,
),
),
FloatingActionButton(
child: Text('post'),
backgroundColor: Colors.pink,
onPressed: (){
handleSubmit();
},
),
],
),
),
),
),
如果我需要提供任何其他帮助,请告诉我。提前致谢。
您可以将表单制作成其他页面并导航到该页面,或作为 Dialog
, and show it over current page using showDialog
。
值可以通过共享模型从 page/dialog 返回,使用 BLoC 模式或通过 Navigator.of(context).pop
。
我想在我的 appBar 中使用一个图标来打开我的表单。目前我的表单位于我的应用程序主体(列)中。我怎样才能做到这一点,而不是在正文中使用表单,我可以点击图标,然后会出现一个弹出窗口,有点像写推文?
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Social App'),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: IconButton(icon: Icon(Icons.add), onPressed: (){})
),
],
),
body: Column(
children: <Widget>[
Flexible(
flex: 0,
child: Card(
child: Form(
key: formKey,
child: Flex(
direction: Axis.vertical,
children: <Widget>[
ListTile(
leading: Icon(Icons.subject),
title: TextFormField(
initialValue: '',
onSaved: (val) => board.subject = val,
validator: (val) => val == "" ? val: null,
),
),
ListTile(
leading: Icon(Icons.message),
title: TextFormField(
initialValue: '',
onSaved: (val) => board.body = val,
validator: (val) => val == "" ? val: null,
),
),
FloatingActionButton(
child: Text('post'),
backgroundColor: Colors.pink,
onPressed: (){
handleSubmit();
},
),
],
),
),
),
),
如果我需要提供任何其他帮助,请告诉我。提前致谢。
您可以将表单制作成其他页面并导航到该页面,或作为 Dialog
, and show it over current page using showDialog
。
值可以通过共享模型从 page/dialog 返回,使用 BLoC 模式或通过 Navigator.of(context).pop
。