본문 바로가기
프로그래밍/Flutter-Dart

[Flutter] Image Picker

by 채연2 2021. 3. 23.

 

 

 

 

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  image_picker:

 

 

 

Button 만들기

Row(
   mainAxisAlignment: MainAxisAlignment.spaceEvenly,
   children: <Widget>[
      FloatingActionButton(
         onPressed: getImageFromCam,
         tooltip: 'Pick Image',
         child: Icon(Icons.add_a_photo),
      ),
      FloatingActionButton(
         onPressed: getImageFromGallery,
         tooltip: 'Pick Image',
         child: Icon(Icons.wallpaper),
      ),
   ],
)

 

 

 

Camera Event

PickedFile? _image;

Future getImageFromCam() async {
   // for camera
   var image = await ImagePicker.platform.pickImage(source: ImageSource.camera);
   setState(() {
      _image = image!;
   });
}

 

 

 

Gallery Event

PickedFile? _image;

Future getImageFromGallery() async {
   // for gallery
   var image = await ImagePicker.platform.pickImage(source: ImageSource.gallery);
   setState(() {
      _image = image!;
   });
}

 

 

 

선택한 이미지 보여주기

Container(
   width: MediaQuery.of(context).size.width,
   height: 200.0,
   child: Center(
      child: _image == null
         ? Text('No image selected.')
         : Image.file(File(_image!.path)),
   ),
)

 

 

 

320x100

 

 

 

결과

 

 

 

 

 

참고 : amazevlley.blogspot.com/2019/02/image-picker-in-flutter-flutter.html

 

Image Picker In Flutter || Amazevalley

In this tutorial you will learn how to pick the image from gallery and capture from camera in flutter. You can explore more it on  image_pi...

amazevlley.blogspot.com

 

 

 

 

320x100

'프로그래밍 > Flutter-Dart' 카테고리의 다른 글

[Flutter] Horizontal Number Picker  (0) 2021.03.23
[Flutter] DatePicker (iOS style)  (0) 2021.03.23
[Flutter] Login App (1)  (0) 2021.03.23
[Flutter] wifi connect 정보  (0) 2021.03.22
[Flutter] Webview JavaScript Handler 등록  (0) 2021.03.22

댓글