大家好,谢谢你们的时间……我被困在这里 2,3 天了…… 在这里,我在 Textfromields 中做了一个下拉菜单,初始值来自我在其中声明的 api 响应 TexeditingController(文本:snapshot.data.gender)
我的问题是当我去改变值 onTap 键盘隐藏它没有改变但当键盘打开时它可以改变。 !我想在下拉选择时隐藏我的键盘.. 我需要的是我需要在构建方法之外的 textcontroller 中声明我的 api 值是否可能然后告诉我我应该如何在构建方法之外打印我的响应数据
@override
Widget build(BuildContext context) {
return Scaffold(
body: (_isLoading) ? Center(child: CircularProgressIndicator()) :
FutureBuilder<UserUpdate>(
future: _futureProfileupdate,
builder: (context, snapshot) {
if (snapshot.hasData) {
TextEditingController _textEditingControllerGender = TextEditingController(text:
snapshot.data.gender);
var items = ["MALE" , "FEMALE"];
return Form(
key: _formKey,
child: Stack(
children: <Widget>[
SingleChildScrollView(
reverse: true,
child: new Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10,left: 30,right: 30),
child: SizedBox(
height: 65,
child: TextFormField(
onTap: (){
FocusScope.of(context).requestFocus(new FocusNode());
}, // if i remove this iteam is going to print on tetxfiled
focusNode: FocusNode(canRequestFocus: false),
textInputAction: TextInputAction.next,
controller: _textEditingControllerGender,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color: Color(0x3df58634)
)
),
labelText: "GENDER",
labelStyle: GoogleFonts.nunito(
color: const Color(0xfff58634)),
hintText: "GENDER",
hintStyle: GoogleFonts.nunito(
color: const Color(0xfff58634)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
5.0),
borderSide: BorderSide(
color: const Color(0x3df58634),
)
),
suffixIcon: PopupMenuButton<String>(
icon: const Icon(Icons.arrow_drop_down),
onSelected: (String value) {
_textEditingControllerGender.text = value;
},
itemBuilder: (BuildContext context) {
return items
.map<PopupMenuItem<String>>((String value) {
return new PopupMenuItem(
child: new Text(value), value: value);
}).toList();
},
),
),
onSaved: (String value) {
_Gender = value;
},
),
),
),
Padding(
padding: EdgeInsets.only(top: 10.0,left: 230,right: 30),
child: SizedBox(
width: 140,
height: 45,
child: RaisedButton(
onPressed: () {
if (!_formKey.currentState.validate()) {
return;
}
setState(() {
_isLoading = true;
});
Profile(
_textEditingControllerGender.text,
);
},
这是我的 json 数据.... 请帮帮我,我被困在这里 2,3 天了
UserUpdate userUpdateFromJson(String str) =>
UserUpdate.fromJson(json.decode(str));
String userUpdateToJson(UserUpdate data) => json.encode(data.toJson());
class UserUpdate {
UserUpdate({
this.successCode,
this.successMessage,
this.firstName,
this.lastName,
this.email,
this.gender, //i want
thiiss default to my
textfiledd and change when
ii select new
});
factory UserUpdate.fromJson(Map<String,
dynamicc> json) => UserUpdate(
successCode:
jsonn["SuccessCode"],
successMessage:
jsonn["SuccessMessage"],
firstName: json["FirstName"],
lastName: json["LastName"],
email: json["Email"],
gender: json["Gender"],
);
Map<String, dynamic> toJson() => {
"SuccessCode": successCode,
"SuccessMessage":
successMessagee,
"FirstName": firstName,
"LastName": lastName,
"Email": email,
"Gender": gender,
};
}