为什么当我尝试以下操作时会出现错误:
Widget build(BuildContext context) {
return const Scaffold(
appBar: AppBar(title: Text("Verify Email")),
body: Text("Needa verify that email dawg @_@"),
);
}
错误:
The constructor being called isn't a const constructor.
Try removing 'const' from the constructor invocation.
为什么 AppBar 构造函数不是 const?
最佳答案
因为AppBar
widget 包含许多不是常量的属性,因此它也不能是常量,因此它不能接受 const
.
你可以考虑AppBar
小部件,作为更多其他小部件的整个子树,如果其中一个不联系,则整个AppBar
情况则不然。
例如,actions
属性,接受 List<Widget>?
作为参数该列表可以动态更改,对吧?所以它不是恒定的,所以 AppBar
不是。
我希望您明白我想说的,AppBar 是许多属性的子集,这些属性不能是常量,这会影响 AppBar
.
关于flutter - 为什么 appBar 小部件在 flutter 中不恒定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75550553/