[英]Flutter setState 3 positional argument(s) expected, but 1 found error
on Button click, I trying to call setState but VScode generates a bug like below.单击按钮时,我尝试调用 setState 但 VScode 会生成如下错误。 Its Stateful widget and VScode suggested that
setState(mounted, setState, fn);
它的 Stateful 小部件和 VScode 建议
setState(mounted, setState, fn);
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++;
});
},
),
],
),
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.这与 Flutter
framework
文件中定义的冲突。
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.这样你将通过前缀调用它的方法并直接调用 Flutters
setState()
。
More info on import prefixes: https://dart.dev/guides/language/language-tour#libraries-and-visibility有关导入前缀的更多信息: https : //dart.dev/guides/language/language-tour#libraries-and-visibility
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.