[Flutter]ModalBottomSheetの高さを最大にするには?

Flutter

どうも、ちょげ(@chogetarou)です。

ModalBottomSheetの高さを最大にする方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

ModalBottomSheetの高さを最大にするには、まずshowModalBottomSheetの引数「isScrollControlled」に「true」を指定します。

showModalBottomSheet(
  isScrollControlled: true,
  context: context,
  builder: (BuildContext context) {
    return Widget();
  },
);

次に、BottomSheetとして表示するウェジェットをContainerもしくはSizedBoxのchildに指定します。

そして、ContainerもしくはSizedBoxの引数「height」に「double.infinity」を指定します。

showModalBottomSheet(
  isScrollControlled: true,
  context: context,
  builder: (BuildContext context) {
    return Container(
      height: double.infinity,
      child : Widget()
    );
  },
);

これでModalBottomSheetの高さを最大にすることが出来ます。

使用例
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showModalBottomSheet(
              isScrollControlled: true,
              context: context,
              builder: (BuildContext context) {
                return Container(
                  height: double.infinity,
                  color: Colors.green,
                  alignment: Alignment.center,
                );
              },
            );
          },
          child: Text('Show'),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました