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);
}
});
}