how to display a error message when the user didn’t choose an item on DropdownMenuItem?

  android, android-studio, dart, firebase, flutter

I try to collect data in firestore from my Flutter app. With the following code: my question is how to display a error message when the user didn’t choose an item on DropdownMenuItem?

 body: Form(
          key: _formKeyValue,
          child: ListView(
            padding: EdgeInsets.symmetric(horizontal: 12.0),
            children: <Widget>[
              SizedBox(height: 20.0),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  DropdownButton(
                    items: _specialite
                        .map((value) => DropdownMenuItem(
                              child: Text(
                                value,
                                textAlign: TextAlign.center,
                                style: TextStyle(color: Colors.black),
                              ),
                              value: value,
                            ))
                        .toList(),
                    onChanged: (selectedAccountType) {
                      print('$selectedAccountType');
                      setState(() {
                        medicalType = selectedAccountType;
                      });
                    },
                    value: medicalType,
                    isExpanded: false,
                    hint: Text(
                      'choisissez la spécialité',
                      style: TextStyle(color: Colors.black),
                    ),
                  )
                ],
              ),
             
              ....
              ....

i used this answer https://stackoverflow.com/a/59746301/15400156 but nothing displayed on screen.

Source: Android Questions

LEAVE A COMMENT