首页 > 解决方案 > '列表' 不是类型 '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');
        },
      ),
    );
  }
}

标签: flutterdart

解决方案


.cast()像这样使用

void main() {
  List a = [];
  List<String> b;
  
//   b = a; not working
  b = a.cast();
}

推荐阅读