Flutter 系统相册 图片选择

iOS需要再项目内配置plist文件,申请访问权。

    NSPhotoLibraryUsageDescription
    Example usage description
    NSCameraUsageDescription
    Example usage description
import 'package:image_picker/image_picker.dart';
import 'dart:io';
  Future _imageFile;

  void _selectedImage() {
    setState(() {
      _imageFile = ImagePicker.pickImage(source: ImageSource.gallery);
    });
  }

  Widget _previewImage() {
    return FutureBuilder(
        future: _imageFile,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.connectionState == ConnectionState.done &&
              snapshot.data != null) {
            return new ClipOval(
              child: SizedBox(
                width: 70.0,
                height: 70.0,
                child: Image.file(snapshot.data, fit: BoxFit.cover)
              ),
            );
          } else {
            return new Image.asset("images/icon_tabbar_mine_normal.png", height: 70.0, width: 70.0);
          }
        });
  }

你可能感兴趣的:(Flutter 系统相册 图片选择)