Flutter 颤振:是否允许容器内溢出?

Flutter 颤振:是否允许容器内溢出?,flutter,flutter-layout,Flutter,Flutter Layout,是否可以允许容器内溢出,而不使该内容可滚动?例如: Container( height: 100, width: MediaQuery.of(context).size.width, child: Row( children: List.generate(10, (i) => Container(height: 100.0, width: 300).toList(); ), ) 我知道它在发行版中理论上可以正常工作,但我希望在调试时抑制溢出警告 我已尝试在Ove

是否可以允许容器内溢出,而不使该内容可滚动?例如:

Container(
  height: 100,
  width: MediaQuery.of(context).size.width,
  child: Row(
    children: List.generate(10, (i) => Container(height: 100.0, width: 300).toList();
   ),
)
我知道它在发行版中理论上可以正常工作,但我希望在调试时抑制溢出警告


我已尝试在OverflowBox()中包装容器(),但它仍然显示溢出警告。我尝试过的其他方法都使列表可滚动-它需要保持固定。

使用SingleChildScrollView,将scrollDirection设置为Axis.horizontal,但我建议使用ListViewBuilder

Container(
          height: 100,
          width: MediaQuery.of(context).size.width,
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: List.generate(
                10,
                (i) => Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                ),
              ).toList(),
            ),
          ),
        ),
ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 100,
              itemBuilder: (context, i) {
                return Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                );
              },
            )
使用ListviewBuilder

Container(
          height: 100,
          width: MediaQuery.of(context).size.width,
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: List.generate(
                10,
                (i) => Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                ),
              ).toList(),
            ),
          ),
        ),
ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 100,
              itemBuilder: (context, i) {
                return Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                );
              },
            )
编辑:包装小部件将完成这一任务

SizedBox(
        height: 100,
        width: MediaQuery.of(context).size.width,
        child: Wrap(
          clipBehavior: Clip.hardEdge,
          direction: Axis.horizontal,
          children: List.generate(
            10,
            (i) => Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            ),
          ).toList(),
        ),
      ),

使用scrollDirection设置为Axis.horizontal的SingleChildScrollView,但我建议使用ListViewBuilder

Container(
          height: 100,
          width: MediaQuery.of(context).size.width,
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: List.generate(
                10,
                (i) => Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                ),
              ).toList(),
            ),
          ),
        ),
ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 100,
              itemBuilder: (context, i) {
                return Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                );
              },
            )
使用ListviewBuilder

Container(
          height: 100,
          width: MediaQuery.of(context).size.width,
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: List.generate(
                10,
                (i) => Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                ),
              ).toList(),
            ),
          ),
        ),
ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 100,
              itemBuilder: (context, i) {
                return Container(
                  height: 100.0,
                  width: 300,
                  margin: EdgeInsets.all(8),
                  color: Colors.green,
                );
              },
            )
编辑:包装小部件将完成这一任务

SizedBox(
        height: 100,
        width: MediaQuery.of(context).size.width,
        child: Wrap(
          clipBehavior: Clip.hardEdge,
          direction: Axis.horizontal,
          children: List.generate(
            10,
            (i) => Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            ),
          ).toList(),
        ),
      ),

要使列表不可滚动,请在ListView中使用
NeverScrollableScrollPhysics()

比如说

ListView.builder(
          physics: NeverScrollableScrollPhysics(),
          scrollDirection: Axis.horizontal,
          itemCount: 100,
          itemBuilder: (context, i) {
            return Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            );
          },
        ),

要使列表不可滚动,请在ListView中使用
NeverScrollableScrollPhysics()

比如说

ListView.builder(
          physics: NeverScrollableScrollPhysics(),
          scrollDirection: Axis.horizontal,
          itemCount: 100,
          itemBuilder: (context, i) {
            return Container(
              height: 100.0,
              width: 300,
              margin: EdgeInsets.all(8),
              color: Colors.green,
            );
          },
        ),

使用listviewbuilder widgetUse listviewbuilder WidgetHanks获得答案-尽管我需要内容不可滚动。我想知道这是否可能与颤振(没有SDK抱怨)?很好的解决方案,谢谢你。谢谢你的回答-虽然我需要的内容是不可滚动的。我想知道这是否可能与颤振(没有SDK抱怨)?很好的解决方案,谢谢。