Flutter picture selection image_picker (official) plug-in use detailed explanation

Flutter picture selection image_picker (official) plug-in use detailed explanation (IOS self-test)

View the latest version of image_picker GitHub:
https://github.com/flutter/plugins
Go down and find image_picker to see the latest version

First import dependencies:

# 图片选择器
image_picker: ^0.6.7+17

how to use:

Directly on the code:

//实例化选择图片
final ImagePicker picker = new ImagePicker();
//用户本地图片
File _userImage;//存放获取到的本地路径
//异步吊起相机拍摄新照片方法
Future _getCameraImage() async {
  final cameraImages = await picker.getImage(source: ImageSource.camera);
  if (mounted) {
    setState(() {
      //拍摄照片不为空
      if (cameraImages != null) {
        _userImage = File(cameraImages.path);
        print('你选择的路径是:${_userImage.toString()}');
        //图片为空
      } else {
        print('没有照片可以选择');
      }
    });
  }
}
Future _getImage() async {
  //选择相册
  final pickerImages = await picker.getImage(source: ImageSource.gallery);
  if(mounted){
    setState(() {
      if(pickerImages != null){
        _userImage = File(pickerImages.path);
        print('你选择的本地路径是:${_userImage.toString()}');
      }else{
        print('没有照片可以选择');
      }
    });
  }
}

Core code:

//Call the camera to take pictures
final cameraImages = await picker.getImage(source: ImageSource.camera);
//Select the album
final pickerImages = await picker.getImage(source: ImageSource.gallery);

Then use a button or something to get a click event. The
image path needs to be connected with the File type.

It should be noted that the
pictures taken by this Demo will not be saved locally

Effect picture:
Insert picture description here
Insert picture description here

Follow me and grow together!
-As.Kai

Guess you like

Origin blog.csdn.net/qq_42362997/article/details/112283982