Image Picker
는 사진첩에서 이미지를 가져오거나 새롭게 카메라로 이미지를 찍어서 가져올 때 사용한다.
dependencies:
image_picker: ^1.0.5
ios/Runner/Info.plist
에 //추가 ...
부분 추가
<plist version="1.0">
<dict>
.
.
.
// 추가
<key>NSCameraUsageDescription</key>
<string>Used to demonstrate image picker plugin</string>
<key>NSMicrophoneUsageDescription</key>
<string>Used to capture audio for image picker plugin</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Used to demonstrate image picker plugin</string>
</dict>
</plist>
(<string></string>
은 설명인듯..?)
ImagePicker
객체와 이미지를 담을 변수 선언 final ImagePicker picker = ImagePicker();
List<XFile?> multiImage = []; // 여러장을 저장할 변수
XFile? image; //1개 불러올 변수
void getMultiImage() async {//이미지 여러개 불러오기
List<XFile?> images = await picker.pickMultiImage();
setState(() {
multiImage = images;
});
}
void getGalleryImage() async {//이미지 갤러리에서 불러오기
XFile? singleimage = await picker.pickImage(source: ImageSource.gallery);
setState(() {
image = singleimage;
});
}
void getCameraImage() async {//이미지 카메라로 찍은 후 가져오기
XFile? singleimage = await picker.pickImage(source: ImageSource.camera);
setState(() {
image = singleimage;
});
}
이미지의 path를 통해 보여줄 수 있다.
Center(
child:
image != null ? Image(image: FileImage(File(image!.path))) : null,
),
참조
찌김이
dosilv.log