This code is responsible for editing the user profile. The bottom line is that the user can go to the settings, change the country, city, and these changes will be saved.

But my problem is that the dropdown box (first Pading in code) does not save the value (i.e. the user profile is empty). In the second field (second Pading) I use the controller and the data is successfully updated. Tell me how to make the updated data from the drop-down list saved in the user profile?

class EditAddressFormPage extends StatefulWidget {
  const EditAddressFormPage({Key? key}) : super(key: key);
  EditPhoneFormPageState createState() {
    return EditPhoneFormPageState();

class EditPhoneFormPageState extends State<EditAddressFormPage> {
  final _formKey = GlobalKey<FormState>();
  final addressCountryController = TextEditingController();
  final addressCityController = TextEditingController();
  var user = UserData.myUser;

  String? selectedValue;
  List<String> items = [

  void dispose() {

  void updateCountry(String country) {
    String formattedPhoneNumber = country.substring(0,country.length);
    user.address_country = formattedPhoneNumber;

  void updateCity(String city) {
    String formattedPhoneNumber = city.substring(0, city.length);
    user.address_city = formattedPhoneNumber;

  _goBack(BuildContext context) {

  Widget build(BuildContext context) {
    return Scaffold(
        body: Form(
          key: _formKey,
          child: Column(
              children: <Widget>[
                const SizedBox(height: 15),
                const Align(
                    child: SizedBox(
                        width: 270,
                        child: Text("What is your new address?",
                          style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                    padding: EdgeInsets.only(top: 20),
                    child: DropdownButtonHideUnderline(
                      child: DropdownButton2(
                        hint: Text('Select country', style: TextStyle(
                          fontSize: 16,
                          color: Theme.of(context).hintColor,),),
                        items: => DropdownMenuItem<String>(
                          value: item,
                          child: Text(
                            style: const TextStyle(fontSize: 14,),),)).toList(),
                        value: selectedValue,
                        onChanged: (value) {
                          setState(() {
                            selectedValue = value as String;});},
                        buttonHeight: 40,
                        buttonWidth: 320,
                        itemHeight: 40,

                    padding: EdgeInsets.only(top: 0),
                    child: SizedBox(
                        height: 100,
                        width: 320,
                        child: TextFormField(
                          // Handles Form Validation
                          validator: (value) {
                            if (value == null || value.isEmpty) {
                              return 'Please enter your city';
                            return null;
                          controller: addressCityController,
                          decoration: const InputDecoration(
                            labelText: 'City',
                    padding: EdgeInsets.only(top: 50),
                    child: Align(
                        alignment: Alignment.bottomCenter,
                        child: SizedBox(
                          width: 320,
                          height: 50,
                          child: ElevatedButton(

                            onPressed: () {
                              // Validate returns true if the form is valid, or false otherwise.
                              if (_formKey.currentState!.validate() ) {
                            style: ElevatedButton.styleFrom(
                            child: const Text(
                              style: TextStyle(fontSize: 15),

enter image description here

Solution 1: Usama majid

What type of data do you want to save ? you want to save the item number and show it on the user profile screen but where? There is a work around though. Use shared_preferences: ^2.0.13 and save the data in the local db so even if your app is terminated you can access the data.

Solution 2: Abhishek Thakur

  1. Solution Inside Update Button

Change this




You are not setting value of addressCountryController.text and trying to update the country name using controller.

  1. Solution

    addressCountryController.text = selectedValue;

you can add this line into onChanged function of dropdown button, which will update the selected country name to addressCountryController controller.