【问题标题】:'List<dynamic>' is not a subtype of type 'List<Water>' in type cast“List<dynamic>”不是类型转换中“List<Water>”类型的子类型
【发布时间】:2021-05-08 08:34:29
【问题描述】:

我想将数据总和显示为字符串,但出现错误。

“列表”不是类型转换中“列表”类型的子类型 在第 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');
        },
      ),
    );
  }
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    像这样使用.cast()

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

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2021-08-29
      • 2019-12-31
      • 2022-12-03
      • 2021-10-23
      相关资源
      最近更新 更多