[Flutter]アイコン(Icon)をContainerのサイズに合わせるには?

Flutter

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

アイコンをContainerのサイズに合わせる方法を紹介します。

スポンサーリンク

方法

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

アイコンをContainerのサイズに合わせるには、まずIconウェジェットを「FittedBox」の「child」に指定します。

そして、FittedBoxの引数「fit」に「BoxFit.fll」を指定します。

Container(
  child: FittedBox(
    child: Icon(/*アイコン*/),
    fit: BoxFit.fill,
  ),
),

これでアイコンをコンテナのサイズに合わせることが出来ます。

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          width: 200,
          height: 200,
          child: FittedBox(
            child: Icon(Icons.flutter_dash),
            fit: BoxFit.fill,
          ),
        ),
      ),
    );
  }

コメント

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