Skip to content

Flutter 背景画像の設定方法

Flutterで背景画像を設定する方法をメモしておきます。今回はContainerに背景画像を設定します。

画像を追加

画像をassetsフォルダに置き、pubspec.yamlに追記します。

assets:
  - assets/images/sample.jpg

BoxDecorationを使用する

ContainerのdecorationにBoxDecorationを設定します。

Container(
  decoration: const BoxDecoration(
    image: DecorationImage(
      image: AssetImage('images/sample.jpg'),
      fit: BoxFit.cover,
    ),
  ),
)

以上で完成です。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です