flutter - '列表' 不是类型 'List 的子类型' 在类型转换中
问题描述
我想将数据总和显示为字符串,但出现错误。
“列表”不是类型转换中“列表”类型的子类型在第 11 行
我正在使用 Hive 作为数据库。
你能帮我解决错误吗?
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: Center(
child: ValueListenableBuilder(
valueListenable: getBoxValueListeneable(),
builder: (context, box, _) => Text(
sumWater(box.get(formatTimeToString(DateTime.now()))).toString(),
style: Theme.of(context).textTheme.headline2)),
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () async {
Navigator.pushNamed(context, '/addWaterBox');
},
),
);
}
}
解决方案
.cast()
像这样使用
void main() {
List a = [];
List<String> b;
// b = a; not working
b = a.cast();
}
推荐阅读
- pandas - 熊猫中循环的矢量化
- android - 需要 TensorFlow 建议
- java - 是否存在通过/失败设计模式?
- python - 从 django 中的字典解析 html 中的值
- node.js - 如何将此 MongoDB 结果重组为正确的格式?
- javascript - 从整个表单而不是单个元素中引用数据
- swift - Swift Firebase Query 由数据库中的每次更改启动
- javascript - GLSL:将可变数量的纹理发送到 sampler2D
- xpages - 在网站上显示 alt 标签
- amazon-web-services - 在 AWS SSM 中检索命令调用