flutter - 为什么这会给我一个错误?以及如何修复它(上下文错误)
问题描述
我在其他地方使用了这个代码行,但它没有给出错误
AutoSizeText(
"عنوان"
,maxLines: 1
,overflow: TextOverflow.ellipsis,
minFontSize: 10,
style:GoogleFonts.rubik(fontSize: 25,color: Theme.of(context).indicatorColor,fontStyle: FontStyle.normal,fontWeight: FontWeight.w500),
),
解决方案
generateItem()
您在状态类之外提取了小部件, _picturesState
.
因此,您必须context
将该状态类的作为参数传递给generateItem()
. 然后您可以在Theme.of(context)
.
您的最终解决方案是:
Card generateItem(BuildContext context) {
return Card(
//..
);
}
当您调用此小部件时,只需将上下文作为参数传递,例如:
return Container(
child: Column(
children:[
generateItem(context);
]
)
);
这应该在你的状态类中,它有自己的上下文。
推荐阅读
- angular - 更改空消息多选启动
- javascript - 在反应中将图像 ID 从组件传递到另一个组件(图像编辑器)的最简单方法是什么?
- powerbi - SSAS 表格是否支持聚合表?
- bootstrap-4 - Navbar side minu 先显示图标然后打开
- flutter - Flutter:如何找到错误的位置,构建错误,未找到:'dart:html'?
- deep-learning - flax (google) 和 dm-haiku (deepmind) 之间的主要区别是什么?
- javascript - 为什么 chrome.tabs.executeScript 方法的回调结果总是返回一个空对象?
- javascript - 删除动态附加的事件监听器到元素
- javascript - Promise.all 不等待最终结果
- html - html,css,在foreach循环中基于单元格值的背景颜色为红色