DropdownButton

A DropdownButton is a widget in Flutter that allows users to select an option from a dropdown menu.

ValueListenableBuilder(
            //create a valueListenable to be updated when choosing a language
            valueListenable: _listenable,
            builder: (context, value, child) {
              //create the language drop down menu
              return DropdownButton<String>(
                dropdownColor: Color.fromARGB(255, 47, 191, 164),
                //the initial value as the Language variable
                value: Idioma,
                //when it changes
                onChanged: (newValue) {
                  //change the Language variable
                  Idioma = newValue.toString();
                  //change the _listenable variable so that it is updated
                  _listenable.value++;
                },
                // for each item in the list _languages we create a DropdownmenuItem
                items: _idiomas.map((idioma) {
                  return DropdownMenuItem<String>(
                    //value is language
                    value: idioma,
                    //the content is a text with the language
                    child: Text(
                      idioma,
                      style: TextStyle(color: Colors.white),
                    ),
                  );
                }).toList(),
              );
            })

Last updated