【问题标题】:Items in a row overflowing连续项目溢出
【发布时间】:2020-07-04 02:39:08
【问题描述】:

我的列表中有 20 项。我希望每行仅显示这些项目 3 或 4 个项目(取决于项目的长度)。

这是我的代码。我得到的输出是:

 Widget build(BuildContext context) {
    var screenSize = MediaQuery.of(context).size;
    var width = screenSize.width;

    return Scaffold(
      body: Container(
        height: 50,
        width: width,
        color: Theme.of(context).primaryColor,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: List.generate(selectedStudentsIT.length, (index) {
            return Wrap(
              children: <Widget>[
                Container(
                  width: 100,
                  child: Card(
                    color: Colors.white,
                    semanticContainer: true,
                    clipBehavior: Clip.antiAliasWithSaveLayer,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    elevation: 5,
                    margin: EdgeInsets.all(10),
                    child: Center(
                      child: Text(
                        "myowntext",// item from the list using the index
                        style: TextStyle(
                          color: Colors.blue,
                          fontWeight: FontWeight.bold,
                          fontSize: 15.0,
                        ),
                      ),
                    ),
                  ),
                )
              ],
            );
          }),
        ),
      ),
    );
  }

我也尝试过使用 WRAP 小部件、Flex 和扩展。但这并没有解决我的问题。

【问题讨论】:

  • 你需要 ListView 而不是 Row

标签: flutter flutter-layout


【解决方案1】:

用 SingleChlidScrollView 包裹你的行。

SingleChildScrollView(scrollDirection:Axis.horizontal,child:Row(children......

【讨论】:

  • 非常感谢。它解决了我的问题。但是,我每行只需要显示 3 个项目。有什么提示吗?
  • 如果是这样,那么您将需要 GridView。
猜你喜欢
  • 2021-09-28
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
  • 1970-01-01
  • 2014-04-17
  • 2021-01-23
  • 2019-04-30
  • 1970-01-01
相关资源
最近更新 更多