본문 바로가기

Flutter

flutter) 이미지 사용

728x90

1.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

  # To add assets to your application, add an assets section, like this:
  assets:
    - images/

 

 

2. Image 위젯으로 사진 가져오기

import "package:flutter/material.dart";

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text('Test'),
          ),
          body: Column(children: [
            Image.asset("images/icon1.png"),
            Image.asset("images/icon2.png"),
            Image.asset("images/icon3.png"),
          ])),
    );
  }
}