どうも、ちょげ(@chogetarou)です。
Containerの背景に画像を表示する方法を紹介します。
方法

Containerの背景に画像を設定するには、まず引数「decoration」に「BoxDecoration」を指定します。
次に、BoxDecorationの引数「DecorationImage」を指定します。
最後に、DecorationImageの引数「image」に画像を設定します。
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: /*画像(Image , AssetImageなど)*/,
),
),
),
以下は、使用例です。
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/images/dog-photo.jpg'),
),
),
),
),
);
}

コメント