플러터 패키지 사이트

https://pub.dartlang.org/flutter
– 이미지 피커: https://pub.dartlang.org/packages/image_picker

pubspec.yaml에 추가

1
2
3
dependencies:
 ...
  image_picker
: ^0.4.6

main.dart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'dart:io';
import 'dart:async';

import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  home: MyHomePage(),
));

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  File _image;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);

    setState(() {
      _image = image;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Image Picker Example'),
      ),
      body: new Center(
        child: _image == null
            ? new Text('No image selected.')
            : new Image.file(_image),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: new Icon(Icons.add_a_photo),
      ),
    );
  }
}

iOS 설정

/ios/Runner/Info.plist에 추가
– NSPhotoLibraryUsageDescription, NSCameraUsageDescription, NSMicrophoneUsageDescription