您generateItem()
在状态类之外提取了小部件,_picturesState
.
因此,您必须context
将该状态类的传递为generateItem()
. 然后您可以在Theme.of(context)
.
您的最终解决方案是:
Card generateItem(BuildContext context) {
return Card(
//..
);
}
当您调用此小部件时,只需将上下文作为参数传递,例如:
return Container(
child: Column(
children:[
generateItem(context);
]
)
);
这应该在你的状态类中,它有自己的上下文。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句