LoginSignup
0
0

More than 3 years have passed since last update.

flutterでアセットに任意の写真を保存して画面に表示させる

Posted at

やりたいこと

  • 任意の写真.jpgをアセットとしてアプリ内に保存しておく。
  • その写真を画面に表示する。

保存用ディレクトリの作成

flutter create を実行すると、

  • android
  • build
  • ios
  • lib

などのディレクトリが生成されるが、
その同列に、自分で任意のディレクトリを作成する。
たとえば

  • images

を作成する。

そのディレクトリ内に、任意の写真、たとえば

sample.jpg

を保存する。

image.png

pubspec.yamlの編集

pubspec.yaml
flutter:内に

  assets:
    - images/sample.jpg

を追記する。

image.png

表示する

Image.asset('images/sample.jpg'),
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