首页 > 解决方案 > 元素类型'Iterable'不能分配给列表类型'Widget'颤动

问题描述

在 Flutter Row of List 中渲染图像列表时出现此错误

import 'package:flutter/material.dart';

import '../../helper/mapIndexed.dart';

const List imageList = [
  'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697109/e42avkuozkqhh8u3dh70.png',
  'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697073/ncuy4b9rnhrwjdwkp6dy.png',
  'https://res.cloudinary.com/du8msdgbj/image/upload/w_560,h_240,,a_ignore,q_auto,f_auto/v1609697374/wf6qw4izw2mi1okmex39.png'
];

class SilpleCarousel extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return Row(
     children: [
    // here is the issue
       imageList.mapIndexed((e, i) => Container())
     ],
   );
 }
}

标签: flutterdart

解决方案


如果我们在 List 上使用 spreed 运算符...,我们可以克服这个

 return Row(
    children: [
    // here we can spreed ...
      ...imageList.mapIndexed((e, i) => Container())
    ],
  );

推荐阅读