1

on Button click, I trying to call setState but VScode generates a bug like below. Its Stateful widget and VScode suggested that setState(mounted, setState, fn);

1

 Row(
     mainAxisAlignment: MainAxisAlignment.spaceEvenly,
     children: [
                    IconButton(
                      icon: Icon(
                        Icons.rounded_corner,
                      ),
                      onPressed: () {
                        setState(() {
                          selectedStock--;
                        });
                      },
                    ),
                    Text(selectedStock.toString()),
                    IconButton(
                      icon: Icon(
                        Icons.rounded_corner,
                      ),
                      onPressed: () {
                        // setState(mounted, setState, fn);
                        setState(() {
                          selectedStock++;
                        });
                      },
                    ),
                  ],
                ),
OMi Shah
  • 5,768
  • 3
  • 25
  • 34
dokind
  • 249
  • 3
  • 15

1 Answers1

1

I had the same issue. It turned out that the problem was this import:

import 'package:html_editor_enhanced/utils/utils.dart';

It defines the following method:

void setState(
    bool mounted, void Function(Function()) setState, void Function() fn) {
  if (mounted) {
    setState.call(fn);
  }
}

which conflicts with the one defined in Flutter framework file.

In my case it turned out I didn't even need that import so I just deleted it. If you do need this import you can give it a prefix:

import 'package:html_editor_enhanced/utils/utils.dart' as utils;

This way you will call it's methods through the prefix and call Flutters setState() directly.

More info on import prefixes: https://dart.dev/guides/language/language-tour#libraries-and-visibility

AXE
  • 8,335
  • 6
  • 25
  • 32
  • This worked for me: I deleted this import 'package:html_editor_enhanced/utils/utils.dart'; it worked after – blue492 Mar 01 '22 at 10:03