LoginSignup
0
0

More than 1 year has passed since last update.

【flutter攻略】画像出力でつまずいてしまった。

Posted at

assset直下に画像を入れる場合の記事はあるけど、、と思ったそこのあなた。
こちらのファイル構造をご覧ください。求めていたのはこちらのファイル構造ですよね??

ファイル構造

  • Assets/
    • Images/
      • sample1.png
    • Fonts/
      • sample.ttf

意外とassets直下に画像を入れる場合や、プロジェクト直下にimagesフォルダを置く場合の出力方法を書いてる記事が多かったので、こちらのファイル構造での出力方法を説明します。

pubspec.yaml
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - assets/
    - assets/images/

説明は入りませんね。こちらをコピーして貼り付ければ、assets直下のimagesフォルダ内全てが使用可能となります。
yamlファイルに変更を加えたら必ずflutter pub getをこないましょう。

画像の指定方法は、こんな感じですかね。

sample.dart
    child: SizedBox(
        width: 300,
        child: Image.asset(
            'assets/images/sample1.png'
        )
    ),

パスには必ずassetsも追加してあげましょう。

スクリーンショット 2022-10-18 21.18.01.png
しっかりでましたね。これにて一件落着!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0