flutter - 列表不是 List 类型的子类型?
问题描述
我正在尝试 CarouselSlider。我想制作顶部的 Carousel Slider,底部的 TextFormField。我持有一个图像路径列表selected
并发送到屏幕,如下所示:
ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed(
OcrScreen.routeName,
arguments: {'image': selected},
);
},
之后,我在其他屏幕上进行辩论,如下所示:
final args = ModalRoute.of(context)!.settings.arguments as Map;
final images=args['image'];
之后
我将此列表放入 CarouselSlider:
return Scaffold(extendBodyBehindAppBar: false,
appBar: AppBar(
title: const Text('OCR'),
elevation: 0,
backgroundColor: Colors.transparent,
),
body:Column(children:[Container(
child: CarouselSlider(
options: CarouselOptions(),
items: images
.map((image) => Container(
child: Center(
child:
Image.file(File(image),fit: BoxFit.cover, width: 1000)),
))
.toList(),
)),TextFormField(
keyboardType: TextInputType.multiline,
controller: _titleController,
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Colors.black),
maxLines: 20,
decoration: InputDecoration(
filled: true,
isDense: true,
contentPadding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
fillColor: Colors.white,
))]
));
}
我得到的 List 不是 List 类型的子类型?错误,我找不到此错误的解决方案,谁能帮我找到解决方案?
解决方案
似乎这就是您收到此错误的原因,因为args['image']
应该是 type 。尝试以这种方式创建变量。null
items
List<Widget>
final List<String> images = args['image'] ?? [];
但是,您可能需要在images.isNotEmpty
映射之前先检查一下。
推荐阅读
- django - 什么时候应该缓存什么数据?
- julia - 在 Julia 中对多变量函数进行数值积分的问题 WRT 单个变量(使用 hcubature)
- reactjs - 如何反向运行 react-spring 动画?
- cassandra - 如何在 Kubernetes 环境中实现 spark-cassandra 连接器的“repartitionByCassandraReplica”?
- python - Python:Mac 中的 Python 版本
- spring-boot - 如何将@Timed 注释与千分尺测量中的内容联系起来
- c# - 如何在异步方法中返回 SignalRMessage?
- laravel - 如何获取类别的父类别状态仅为活动的数据?
- python - 使用 Paramiko 将 Pandas 数据帧传输到 SFTP
- ruby-on-rails - 如何将 JWT 用作 Doorkeeper 的刷新令牌?