15

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,
                        ),
                      ),
                    ),
                  );
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Badi Ais
  • 161
  • 1
  • 1
  • 3

4 Answers4

56

You misplaced a ')' -->

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

Also, showSnackBar is deprecated, consider using ScaffoldMessenger

ScaffoldMessenger.of(context).showSnackBar(snackBar);
simrat singh
  • 561
  • 3
  • 2
13

Verify in flutter 3.7.1:

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

->

ScaffoldMessenger.of(context).showSnackBar
Ari
  • 153
  • 1
  • 7
0

Fixed my problem by

ScaffoldMessenger.of(context).showSnackBar
Kumar
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 17 '23 at 06:15
-1

That's your line of code: Scaffold.of(context.showSnackBar(snackBar)); You have to put the capital 'S'; would look like this: Scaffold.of(context.showSnackBar(SnackBar));

key
  • 1,334
  • 1
  • 19
  • 39