Flutter showModalBottomSheet改變高度


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM