Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

dropdown - Flutter How To change Api value in DropDownlist

hello guys i m new in flutter and i want set TextEditingController initial value outside build method ! can any one help me ?? i am stuck here 2,3 days...! actully what happn in this code when i hide keyboard i cant change the initial text value ...! if i unhide keyboard it can changing...! so what i want is to declaire my api response value outside build method in TextEditingController(text:)

      @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,
                              
                            );
                          }

here is my response

    String userUpdateToJson(UserUpdate data) => json.encode(data.toJson());

 class UserUpdate {
 UserUpdate({
 this.successCode,
 this.successMessage,
 this.email,
 this.gender,  //i want thiis default to my textfiled and change when i select new
 this.birthDate,

 });

 String successCode;
 String successMessage;
String email;
dynamic gender;
String birthDate;


  factory UserUpdate.fromJson(Map<String, dynamic> json) => UserUpdate(
  successCode: json["SuccessCode"],
  successMessage: json["SuccessMessage"],
  email: json["Email"],
  gender: json["Gender"],
    birthDate: json["BirthDate"],

  );

  Map<String, dynamic> toJson() => {
  "SuccessCode": successCode,
  "SuccessMessage": successMessage,
  "Email": email,
  "Gender": gender,
   "BirthDate": birthDate,

     };
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...