Row flutter 内的ListViewBuiler

问题描述 投票:0回答:3

我试图在一行中添加一个列表视图,但我得到了这个错误

我在行中有两个小部件,第一个小部件带有一列,第二个小部件是返回另一个小部件的列表视图构建器。

我正在尝试使该行如下图所示

这是我的代码

body: SingleChildScrollView(
        child: Column(
          children: [
            Row(
              children: [
                Column(
                  children: [
                    Stack(
                      children: [
                        Container(
                          height: 60,
                          width: 60,
                          decoration: const BoxDecoration(
                              color: Colors.red,
                              shape: BoxShape.circle,
                              image: DecorationImage(
                                  image: AssetImage("assets/images/meee.jpg"))),
                        ),
                        Positioned(
                          bottom: 0,
                          right: 0,
                          child: Container(
                            padding: EdgeInsets.all(5),
                            decoration: BoxDecoration(
                                color: Colors.blue, shape: BoxShape.circle),
                            child: Text(
                              "+",
                              style: TextStyle(color: Colors.white),
                            ),
                          ),
                        )
                      ],
                    ),
                    const SizedBox(
                      height: 7,
                    ),
                    const Text(
                      "Your Story",
                      style: TextStyle(color: Colors.white, fontSize: 13),
                    )
                  ],
                ),
                ListView.builder(
                  itemCount: 3,
                  scrollDirection: Axis.horizontal,
                  itemBuilder: (BuildContext context, int index) {
                    return __buildStory();
                  },
                ),
              ],
            ),
          ],
        ),
      ),
 
flutter listview flutter-layout row
3个回答
0
投票

你尝试改变这条线吗

ListView.builder(

用这条线

ListView.builder(shrinkWrap: true,

如果不起作用,请考虑将您的

ListView.builder
小部件包装在
Flexible
小部件中

Flexible(child:

0
投票

由于

ListView
需要
Row
中的所有剩余空间,请用
ListView.builder
包裹
Expanded
。还可以在
shrinkWrap:true
中使用
ListView

mainAxisSize: MainAxisSize.min
添加到
Column


body: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Row(
              children: [
                Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Stack(
                      children: [
                        Container(
                          height: 60,
                          width: 60,
                          decoration: const BoxDecoration(
                              color: Colors.red,
                              shape: BoxShape.circle,
                              image: DecorationImage(
                                  image: AssetImage("assets/images/meee.jpg"))),
                        ),
                        Positioned(
                          bottom: 0,
                          right: 0,
                          child: Container(
                            padding: EdgeInsets.all(5),
                            decoration: BoxDecoration(
                                color: Colors.blue, shape: BoxShape.circle),
                            child: Text(
                              "+",
                              style: TextStyle(color: Colors.white),
                            ),
                          ),
                        )
                      ],
                    ),
                    const SizedBox(
                      height: 7,
                    ),
                    const Text(
                      "Your Story",
                      style: TextStyle(color: Colors.white, fontSize: 13),
                    )
                  ],
                ),
                Expanded(
                child: ListView.builder(
                    shrinkWrap: true,
                    itemCount: 3,
                    scrollDirection: Axis.horizontal,
                    itemBuilder: (BuildContext context, int index) {
                      return __buildStory();
                    },
                  ),
                ),
              ],
            ),
          ],
        ),
      ),

0
投票

这应该可以解决你的问题

SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Row(
               children: List.generate(3,
                (index) => widget)),
             )
© www.soinside.com 2019 - 2024. All rights reserved.