如何用flutter中的小部件列表替换图像列表?

时间:2019-06-13 14:03:50

标签: list flutter

您好,我尝试使用此Tinder Card插件,但示例使用列表字符串显示每张新卡的资产,但我尝试用更多内容(如文本,图像等)来修改容器

这是示例:

 List<String> welcomeImages = [
    "assets/welcome0.png",
    "assets/welcome1.png",
  ];

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
          child: Container(
              height: MediaQuery.of(context).size.height * 0.6,
              child: new TinderSwapCard(
             ...
                cardBuilder: (context, index) => Card(
                      child: Image.asset('${welcomeImages[index]}'),
                    ),
              ))),
    );

我搜索如下内容:

  List<widget> my_list_of_widget= [
        widget1()
        widget2()
      ];

    widget1(){
    return column[
     text 
     image
     etc 
    ]
   }

   widget2(){
   return column[
    text 
    image
    etc 
    ]
  }

      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          body: new Center(
              child: Container(
                  height: MediaQuery.of(context).size.height * 0.6,
                  child: new TinderSwapCard(
               ...
                    cardBuilder: (context, index) => Card(
                          child: my_list_of_widget
                        ),
                  ))),
        );

我找到了这个其他的火种卡插件,但存在相同的示例问题:

new Swiper(
    itemBuilder: (BuildContext context, int index) {
      return new Image.network(
        "http://via.placeholder.com/288x188",
        fit: BoxFit.fill,
      );
    },
    itemCount: 2,
    itemWidth: 300.0,
    itemHeight: 400.0,
    layout: SwiperLayout.TINDER,
 )

我需要这样的东西:

new Swiper(
        itemBuilder: (BuildContext context, int index) {
          return children[
          widget 1()  //index1
          widget 2()  //index2
         ]
        },
        itemCount: 2,
        itemWidth: 300.0,
        itemHeight: 400.0,
        layout: SwiperLayout.TINDER,
     )

我成功使用了swiper插件的示例,但我不能使用布局:SwiperLayout.TINDER,如果使用子代:[]

 new Swiper.children(
              viewportFraction: 0.7,
              scale: 0.7,
              autoplay: false,
              loop: true,

              control: new SwiperControl(

                  size: 25.0,
                  color: Colors.pink,
                  padding: const EdgeInsets.all(5.0)),
              pagination: new SwiperPagination(
                  margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
                  builder: new DotSwiperPaginationBuilder(
                      color: Color(0xff7589a2),
                      activeColor: Colors.pink,
                      size: 4.0,
                      activeSize: 8.0)),

              children: <Widget>[

 Text("blablabla1");

 Text("blablabla2");

     ],
   ),
 ),
)

1 个答案:

答案 0 :(得分:0)

尝试一下:

  List<Widget> welcomeWidgets =
      List<Widget>.from(welcomeImages.map((String asset) {
    return Column(
      children: <Widget>[Text(asset), Image.asset(asset)],
    );
  }));