[Flutter]CupertinoのModalBottomSheetの背景色を設定するには?

Flutter

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

CupertinoのModalBottomSheetの背景色を設定する方法を紹介します。

前提

この記事では、「modal_bottom_sheet」パッケージを使っています。

スポンサーリンク

方法

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

CupertinoのModalBottomSheetの背景色を設定するには、、showCupertinoModalBottomSheet関数の引数「backgroundColor」を使います。

具体的な方法としては、引数「backgroundColor」に背景色を設定します。

showCupertinoModalBottomSheet(
  backgroundColor: /*背景色*/,
  context: context,
  builder: (context) {
    return Widget();
  },
);

以下は、使用例です。

使用例
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showCupertinoModalBottomSheet(
              backgroundColor: Colors.blue.withOpacity(0.2),
              context: context,
              builder: (context) {
                return Container(
                  child: ListView.builder(
                    itemBuilder: (context, index) {
                      return Card(
                        child: ListTile(
                          title: Text('Item $index'),
                        ),
                      );
                    },
                    itemCount: 10,
                  ),
                );
              },
            );
          },
          child: Text('Show'),
        ),
      ),
    );
  }

コメント

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