Flutter 只有在重新加载整个应用程序时,DropDownButtonForm字段的选定值才会出现

Flutter 只有在重新加载整个应用程序时,DropDownButtonForm字段的选定值才会出现,flutter,flutter-layout,Flutter,Flutter Layout,我需要此警报对话框以在中显示所选项目 Widget _changePrPar() { showDialog( context: context, builder: (BuildContext context) { return SingleChildScrollView( child: AlertDialog( key: alertDialogKey, title: ListTile(

我需要此警报对话框以在中显示所选项目

Widget _changePrPar() {
  showDialog(
      context: context,
      builder: (BuildContext context) {
        return SingleChildScrollView(
          child: AlertDialog(
            key: alertDialogKey,
            title: ListTile(
              leading: Icon(Icons.account_circle),
              title: Text("Mon premier Dialogue"),
            ),
            content: Form(
              key: formKey,
              child: Column(
                children: <Widget>[
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Nom et Prenom",
                        hintText: "Ex. Ndoume Desmon"),
                    validator: (val) =>
                        val.isEmpty ? "The Name cannot be empty" : null,
                    onSaved: (val) => nomP = val,
                  ),

                  TextFormField(
                      decoration: InputDecoration(
                          labelText: "User Name",
                          hintText: "Ex. desmon215"),
                      validator: (val) => val.isEmpty
                          ? "The user name cannot be empty"
                          : null,
                      onSaved: (val) => pseudo = val),

                  //My Problems start here, the value selected does not appear,
                  ListTile(
                    title: Text(
                      "Gender",
                      style: TextStyle(color: Colors.grey),
                    ),
                    contentPadding: EdgeInsets.symmetric(vertical: 9),
                    subtitle: DropdownButtonFormField<String>(
                      items: Sexe.map((l) => DropdownMenuItem(
                            child: Text(l),
                            value: l,
                          )).toList(),
                      value: sexyVal,
                      onSaved: (val) => sexyVal = val,
                      onChanged: (v) {
                        setState(() {
                          sexyVal = v;
                        });
                      },
                    ),
                  ),
                  TextFormField(
                      decoration: InputDecoration(
                          labelText: "Telephone",
                          hintText: "Ex. 654521455"),
                      validator: (val) =>
                          val.length > 9 && val.startsWith("6")
                              ? null
                              : "The phoe number is not valid..",
                      onSaved: (val) => tel = val),
                  TextFormField(
                      decoration: InputDecoration(
                          labelText: "Email",
                          hintText: "Ex. abc@xyzer.com"),
                      validator: (val) =>
                          val.contains("@") && val.endsWith(".com")
                              ? null
                              : "Invalid e-mail",
                      onSaved: (val) => mailP = val),
                  TextFormField(
                      controller: passCtl,
                      decoration: InputDecoration(
                        suffix: IconButton(
                          icon: Icon(
                            Icons.cancel,
                            color: Colors.grey,
                          ),
                          onPressed: () {
                            passCtl.clear();
                          },
                        ),
                        labelText: "PassWord",
                        hintText: "8 caracters minimum..",
                      ),
                      maxLengthEnforced: true,
                      maxLength: 10,
                      obscureText: true,
                      validator: (val) =>
                          val.length < 8 ? "Password too short" : null,
                      onSaved: (val) => pass = val),
                  TextFormField(
                    controller: dateCtl,
                    decoration: InputDecoration(
                      suffix: IconButton(
                        icon: Icon(
                          Icons.cancel,
                        ),
                        onPressed: () {
                          dateCtl.clear();
                        },
                      ),
                      labelText: "Date of birth",
                      hintText: "Ex. Insert your dob",
                    ),
                    onTap: () async {
                      DateTime date = DateTime(1900);
                      FocusScope.of(context).requestFocus(new FocusNode());
                      date = await showDatePicker(
                          context: context,
                          initialDate: DateTime.now(),
                          firstDate: DateTime(1900),
                          lastDate: DateTime(2100));

                      // pour calculer l'age a partir de la date de naissance
                      age = DateTime.now().difference(date).inDays;
                      Age = (age / 360).floor();
                      _date = date.toIso8601String();
                      dateCtl.text = _date.substring(0, 10);
                    },
                    onSaved: (val) => _date = Age.toString(),
                  ),
                ],
              ),
            ),
            actions: <Widget>[
              FlatButton(
                child: Text("Cancel"),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              FlatButton(
                child: Text("Submit"),
                onPressed: () {
                  final form = formKey.currentState;
                  if (form.validate()) {
                    setState(() {
                      form.save();
                      Navigator.of(context).pop();
                    });
                  }
                },
              )
            ],
          ),
        );
      });
}
Widget_changeprppar(){
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回SingleChildScrollView(
子:警报对话框(
键:alertDialogKey,
标题:ListTile(
前导:图标(图标、账户和圆圈),
标题:文本(“周一总理对话”),
),
内容:表格(
key:formKey,
子:列(
儿童:[
TextFormField(
装饰:输入装饰(
labelText:“名称和名称”,
hintText:“前恩杜姆·德斯蒙”),
验证器:(val)=>
val.isEmpty?“名称不能为空”:null,
onSaved:(val)=>nomP=val,
),
TextFormField(
装饰:输入装饰(
labelText:“用户名”,
hintText:“前desmon215”),
验证程序:(val)=>val.isEmpty
?“用户名不能为空”
:null,
onSaved:(val)=>pseudo=val),
//我的问题从这里开始,选择的值不会出现,
列表砖(
标题:正文(
“性别”,
样式:TextStyle(颜色:Colors.grey),
),
内容填充:边集。对称(垂直:9),
字幕:DropdownButtonFormField(
项目:Sexe.map((l)=>下拉菜单项(
儿童:文本(l),
值:l,
)).toList(),
值:sexyVal,
onSaved:(val)=>sexyVal=val,
一旦更改:(v){
设置状态(){
sexyVal=v;
});
},
),
),
TextFormField(
装饰:输入装饰(
标签文字:“电话”,
hintText:“Ex.654521455”),
验证器:(val)=>
val.length>9&&val.startsWith(“6”)
无效的
:“phoe号码无效..”,
onSaved:(val)=>tel=val),
TextFormField(
装饰:输入装饰(
labelText:“电子邮件”,
hintText:“例如。abc@xyzer.com"),
验证器:(val)=>
val.contains(“@”)和&val.endsWith(“.com”)
无效的
:“无效电子邮件”,
onSaved:(val)=>mailP=val),
TextFormField(
控制器:passCtl,
装饰:输入装饰(
后缀:IconButton(
图标:图标(
图标。取消,
颜色:颜色。灰色,
),
已按下:(){
passCtl.clear();
},
),
labelText:“密码”,
hintText:“最小8个字符…”,
),
马克斯:是的,
最大长度:10,
蒙昧文字:对,
验证器:(val)=>
val.length<8?“密码太短”:null,
保存:(val)=>pass=val),
TextFormField(
控制器:dateCtl,
装饰:输入装饰(
后缀:IconButton(
图标:图标(
图标。取消,
),
已按下:(){
dateCtl.clear();
},
),
标签文字:“出生日期”,
hintText:“例如,插入您的dob”,
),
onTap:()异步{
日期时间日期=日期时间(1900);
FocusScope.of(context).requestFocus(newfocusnode());
日期=等待showDatePicker(
上下文:上下文,
initialDate:DateTime.now(),
firstDate:DateTime(1900),
lastDate:DateTime(2100));
//这是一个生日聚会
年龄=DateTime.now().差异(日期).inDays;
年龄=(年龄/360).floor();
_date=date.toiso8601字符串();
dateCtl.text=_date.substring(0,10);
},
onSaved:(val)=>\u date=Age.toString(),
),
],
),
),
行动:[
扁平按钮(
子项:文本(“取消”),
已按下:(){
Navigator.of(context.pop();
},
),
扁平按钮(
儿童:文本(“提交”),
已按下:(){
最终形式=formKey.currentState;
if(form.validate()){
设置状态(){
form.save();
Navigator.of(context.pop();
class DialogContent extends StatefulWidget {
@override
_DialogContentState createState() => _DialogContentState();
}

class _DialogContentState extends State<DialogContent> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
  child: AlertDialog(
    key: alertDialogKey,
    title: ListTile(
      leading: Icon(Icons.account_circle),
      title: Text("Mon premier Dialogue"),
    ),
    content: Form(
      key: formKey,
      child: Column(
        children: <Widget>[
          TextFormField(
            decoration: InputDecoration(
                labelText: "Nom et Prenom",
                hintText: "Ex. Ndoume Desmon"),
            validator: (val) =>
            val.isEmpty ? "The Name cannot be empty" : null,
            onSaved: (val) => nomP = val,
          ),

          TextFormField(
              decoration: InputDecoration(
                  labelText: "User Name",
                  hintText: "Ex. desmon215"),
              validator: (val) => val.isEmpty
                  ? "The user name cannot be empty"
                  : null,
              onSaved: (val) => pseudo = val),

          //My Problems start here, the value selected does not appear,
          ListTile(
            title: Text(
              "Gender",
              style: TextStyle(color: Colors.grey),
            ),
            contentPadding: EdgeInsets.symmetric(vertical: 9),
            subtitle: DropdownButtonFormField<String>(
              items: Sexe.map((l) => DropdownMenuItem(
                child: Text(l),
                value: l,
              )).toList(),
              value: sexyVal,
              onSaved: (val) => sexyVal = val,
              onChanged: (v) {
                setState(() {
                  sexyVal = v;
                });
              },
            ),
          ),
          TextFormField(
              decoration: InputDecoration(
                  labelText: "Telephone",
                  hintText: "Ex. 654521455"),
              validator: (val) =>
              val.length > 9 && val.startsWith("6")
                  ? null
                  : "The phoe number is not valid..",
              onSaved: (val) => tel = val),
          TextFormField(
              decoration: InputDecoration(
                  labelText: "Email",
                  hintText: "Ex. abc@xyzer.com"),
              validator: (val) =>
              val.contains("@") && val.endsWith(".com")
                  ? null
                  : "Invalid e-mail",
              onSaved: (val) => mailP = val),
          TextFormField(
              controller: passCtl,
              decoration: InputDecoration(
                suffix: IconButton(
                  icon: Icon(
                    Icons.cancel,
                    color: Colors.grey,
                  ),
                  onPressed: () {
                    passCtl.clear();
                  },
                ),
                labelText: "PassWord",
                hintText: "8 caracters minimum..",
              ),
              maxLengthEnforced: true,
              maxLength: 10,
              obscureText: true,
              validator: (val) =>
              val.length < 8 ? "Password too short" : null,
              onSaved: (val) => pass = val),
          TextFormField(
            controller: dateCtl,
            decoration: InputDecoration(
              suffix: IconButton(
                icon: Icon(
                  Icons.cancel,
                ),
                onPressed: () {
                  dateCtl.clear();
                },
              ),
              labelText: "Date of birth",
              hintText: "Ex. Insert your dob",
            ),
            onTap: () async {
              DateTime date = DateTime(1900);
              FocusScope.of(context).requestFocus(new FocusNode());
              date = await showDatePicker(
                  context: context,
                  initialDate: DateTime.now(),
                  firstDate: DateTime(1900),
                  lastDate: DateTime(2100));

              // pour calculer l'age a partir de la date de naissance
              age = DateTime.now().difference(date).inDays;
              Age = (age / 360).floor();
              _date = date.toIso8601String();
              dateCtl.text = _date.substring(0, 10);
            },
            onSaved: (val) => _date = Age.toString(),
          ),
        ],
      ),
    ),
    actions: <Widget>[
      FlatButton(
        child: Text("Cancel"),
        onPressed: () {
          Navigator.of(context).pop();
        },
      ),
      FlatButton(
        child: Text("Submit"),
        onPressed: () {
          final form = formKey.currentState;
          if (form.validate()) {
            setState(() {
              form.save();
              Navigator.of(context).pop();
            });
          }
        },
       )
      ],
     ),
    );
  });
 }
}
showDialog(
....
builder: (context)=> DialogContent()
);