使showModalBottomSheet()高度根据内容调整

4 dart flutter flutter-layout

我试图使 showModalBottomSheet() 的高度自动调整为内容。

我用过FractionallySizedBoxisScrollControlled: true但需要heightFactor提供。

有没有办法根据底部的内容调整底部工作表的高度?

无夜之*_*之星辰 6

  1. 设置;isScrollControlled true
  2. 将列设置mainAxisSizemin;
  3. 将 listView 设置shrinkWraptrue.

例如:

showModalBottomSheet(
  isScrollControlled: true,
  backgroundColor: Colors.blue,
  context: context,
  builder: (context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(width: 100, height: 100, color: Colors.green),
        Container(width: 300, height: 500, color: Colors.red),
        Container(width: 100, height: 100, color: Colors.orange),
      ],
    );
  },
);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述