Flutter 系统相册 图片选择

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

    <key>NSPhotoLibraryUsageDescription</key>
    <string>Example usage description</string>
    <key>NSCameraUsageDescription</key>
    <string>Example usage description</string>
import 'package:image_picker/image_picker.dart';
import 'dart:io';
  Future<File> _imageFile;

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

  Widget _previewImage() {
    return FutureBuilder<File>(
        future: _imageFile,
        builder: (BuildContext context, AsyncSnapshot<File> 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);
          }
        });
  }
    原文作者:GA_
    原文地址: https://www.jianshu.com/p/e1a5e88e9278
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞