showModalBottomSheet改變高度
- 將isScrollControlled設置為true,此時彈窗會全屏展示,再返回一個帶高度的SizedBox,就可以指定彈窗的高度了
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25), topRight: Radius.circular(25))),
isScrollControlled: true,
builder: (context) {
ScrollController controller = ScrollController(
initialScrollOffset: selIndex == null
? 0
: selIndex == -1
? 0
: selIndex * 40);
return SizedBox(
height: 400.h,
child: ListView(
controller: controller,
children: list
?.asMap()
.map((i, e) {
return MapEntry(
i,
LocationItems(
name: isList == false ? e['name'] : e,
isSelected: i == selIndex,
));
})
.values
.toList() as List<Widget>));
})
- 如果想要自適應高度就設置isScrollControlled為true並用SingleChildScrollView嵌套Column或者用Container包裹住ListView
參考:https://blog.csdn.net/qq_28865297/article/details/104776222
https://www.jianshu.com/p/39cfc6cccc02