Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method 'showSnackBar' isn't defined for the type 'BuildContext'

Here i create a DropdownItemMenu which get the element from firebase collection, but it shows me an error

The method 'showSnackBar' isn't defined for the type 'BuildContext'

Container(
                    margin: EdgeInsets.only(left: 16, right: 16),
                    height: MediaQuery.of(context).size.height * 0.10,
                    child: Card(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: DropdownButton<String>(
                          isExpanded: false,
                          style: TextStyle(
                              fontSize: 14, color: Colors.blueGrey),
                          icon: const Icon(Icons.keyboard_arrow_down),
                          underline: Container(color: Colors.transparent),
                          onChanged: (serieValue) {
                            final snackBar = SnackBar(
                                content: Text(
                              'Série selectionnée est $serieValue',
                              style: TextStyle(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 14,
                                  color: Color(0xff11b719)),
                            ));
                            Scaffold.of(context.showSnackBar(snackBar));


                            setState(() {
                              selectedIndexSerie = serieValue;
                            });
                          },
                          value: selectedIndexSerie,
                          hint: Text(
                            'Selectionner une série',
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 14,
                                color: Color(0xff11b719)),
                          ),
                          items: series,
                        ),
                      ),
                    ),
                  );
like image 967
Badi Ais Avatar asked Dec 10 '25 08:12

Badi Ais


1 Answers

You misplaced a ')' -->

Scaffold.of(context).showSnackBar(snackBar);

Also, showSnackBar is deprecated, consider using ScaffoldMessenger

ScaffoldMessenger.of(context).showSnackBar(snackBar);
like image 70
simrat singh Avatar answered Dec 12 '25 01:12

simrat singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!