どうも、ちょげ(@chogetarou)です。
アイコンをContainerのサイズに合わせる方法を紹介します。
方法

アイコンを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,
),
),
),
);
}

コメント