垂直行动正在工作,但水平不起作用

发布于 2025-02-13 03:29:27 字数 1018 浏览 0 评论 0原文

我想在卡小部件中添加listView。它在垂直滚动时起作用,但在水平滚动时不行。我该如何修复?它在小型框中。我尝试了灵活和扩展,但无效。

 return Scaffold(
  appBar: appBar(),
  body: Padding(
    padding: const EdgeInsets.only(top: 5, left: 8, right: 5),
    child: Column(
      children: [
        Card(
          elevation: 0,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
            
              SizedBox(
                height: 100,
                width: 110,
                child: SingleChildScrollView(
                  scrollDirection: Axis.vertical,
                  child: ListView.builder(
                    shrinkWrap: true,
                    physics: const BouncingScrollPhysics(),
                    itemCount: 5,
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(
                        title: TextButton(onPressed: () {}, child: Text(brandName[index])),
                      );
                    },),),)],),),],),),);

I want to add a listview in Card widget. It works when scroll vertically, but not when scroll horizontally. How can I fix it? It is in Sizedbox. I tried flexible and expanded but doesnt work.

 return Scaffold(
  appBar: appBar(),
  body: Padding(
    padding: const EdgeInsets.only(top: 5, left: 8, right: 5),
    child: Column(
      children: [
        Card(
          elevation: 0,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
            
              SizedBox(
                height: 100,
                width: 110,
                child: SingleChildScrollView(
                  scrollDirection: Axis.vertical,
                  child: ListView.builder(
                    shrinkWrap: true,
                    physics: const BouncingScrollPhysics(),
                    itemCount: 5,
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(
                        title: TextButton(onPressed: () {}, child: Text(brandName[index])),
                      );
                    },),),)],),),],),),);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£冰雨忧蓝° 2025-02-20 03:29:27

而是这样做:

/*...*/
SizedBox(
  height: 100,
  width: 110,
  child: ListView.builder(
    scrollDirection: Axis.horizontal,
    shrinkWrap: true,
    physics: const BouncingScrollPhysics(),
    itemCount: 5,
    itemBuilder: (BuildContext context, int index) {
      return SizedBox(
        width: // set a value,
        child: ListTile(
          // for suggestion you don't need `TextButton` here
          // just do `title: Text(brandName[index])` and use the `onTap` function of `ListTile` instead
          title: TextButton(
            onPressed: () {},
            child: Text(brandName[index])
          )
        ),
      );
    },
  ),
)
/*...*/

Do this instead:

/*...*/
SizedBox(
  height: 100,
  width: 110,
  child: ListView.builder(
    scrollDirection: Axis.horizontal,
    shrinkWrap: true,
    physics: const BouncingScrollPhysics(),
    itemCount: 5,
    itemBuilder: (BuildContext context, int index) {
      return SizedBox(
        width: // set a value,
        child: ListTile(
          // for suggestion you don't need `TextButton` here
          // just do `title: Text(brandName[index])` and use the `onTap` function of `ListTile` instead
          title: TextButton(
            onPressed: () {},
            child: Text(brandName[index])
          )
        ),
      );
    },
  ),
)
/*...*/
夏了南城 2025-02-20 03:29:27

用sizedbox()包装listTile,并明确指定ListTile的宽度。

例如。 SIZIEDBOX(宽度:100,Listile(...)),

以更好地理解请参阅此答案

Wrap your ListTile with SizedBox() and explicitly specify the width of ListTile.

eg. SizedBox (width: 100, LisTile(...))

For better understanding refer this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文