Flutter圈子程序员iOS开发进阶

Flutter 系统相册 图片选择

2018-11-05  本文已影响26人  GA_

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);
          }
        });
  }
上一篇 下一篇

猜你喜欢

热点阅读