无法在iOS平台上获取Flatter中的图像
我正在使用下面的代码从Flatter应用程序的gallery中获取图像,它在Android中运行良好,并成功地将图像上传到firebase存储,但在iOS应用程序中使用相同的代码时,当方法“getImage()时,应用程序崩溃'在点击无法在iOS平台上获取Flatter中的图像,ios,swift,flutter,flutter-image,Ios,Swift,Flutter,Flutter Image,我正在使用下面的代码从Flatter应用程序的gallery中获取图像,它在Android中运行良好,并成功地将图像上传到firebase存储,但在iOS应用程序中使用相同的代码时,当方法“getImage()时,应用程序崩溃'在点击容器中的图标按钮时被调用,我在日志中收到以下消息 与设备的连接中断。 Future getImage()异步{ File image=wait ImagePicker.pickImage(源:ImageSource.gallery); 如果(图像!=null){ 设
容器中的图标按钮时被调用,我在日志中收到以下消息
与设备的连接中断。
Future getImage()异步{
File image=wait ImagePicker.pickImage(源:ImageSource.gallery);
如果(图像!=null){
设置状态(){
avatarImageFile=图像;
isLoading=true;
});
}
}
容器(
儿童:中心(
子:堆栈(
儿童:[
(avatarImageFile==null)
?(照片URL!=“”
?材料(
子:CachedNetworkImage(
占位符:(上下文,url)=>容器(
子对象:循环压缩机指示器(
冲程宽度:2.0,
valueColor:AlwaysStoppedAnimation(颜色),
),
宽度:90.0,
身高:90.0,
填充:所有边缘设置(20.0),
),
imageUrl:photoUrl,
宽度:90.0,
身高:90.0,
适合:BoxFit.cover,
),
borderRadius:borderRadius.all(半径.圆形(45.0)),
clipBehavior:Clip.hardEdge,
)
:图标(
Icons.account_圈,
尺寸:90.0,
颜色:灰色,
))
:材料(
子:Image.file(
虚拟图像文件,
宽度:90.0,
身高:90.0,
适合:BoxFit.cover,
),
borderRadius:borderRadius.all(半径.圆形(45.0)),
clipBehavior:Clip.hardEdge,
),
图标按钮(
图标:图标(
图标,照相机,
颜色:原色。不透明度(0.5),
),
onPressed:getImage,
填充:所有边缘设置(30.0),
splashColor:Colors.transparent,
highlightColor:greyColor,
iconSize:30.0,
),
],
),
),
宽度:double.infinity,
裕度:所有边缘集(20.0),
),
确保在info.plist中添加必要的权限,确保在info.plist中添加必要的权限,
Future getImage() async {
File image = await ImagePicker.pickImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
avatarImageFile = image;
isLoading = true;
});
}
}
Container(
child: Center(
child: Stack(
children: <Widget>[
(avatarImageFile == null)
? (photoUrl != ''
? Material(
child: CachedNetworkImage(
placeholder: (context, url) => Container(
child: CircularProgressIndicator(
strokeWidth: 2.0,
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
),
width: 90.0,
height: 90.0,
padding: EdgeInsets.all(20.0),
),
imageUrl: photoUrl,
width: 90.0,
height: 90.0,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(Radius.circular(45.0)),
clipBehavior: Clip.hardEdge,
)
: Icon(
Icons.account_circle,
size: 90.0,
color: greyColor,
))
: Material(
child: Image.file(
avatarImageFile,
width: 90.0,
height: 90.0,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(Radius.circular(45.0)),
clipBehavior: Clip.hardEdge,
),
IconButton(
icon: Icon(
Icons.camera,
color: primaryColor.withOpacity(0.5),
),
onPressed: getImage,
padding: EdgeInsets.all(30.0),
splashColor: Colors.transparent,
highlightColor: greyColor,
iconSize: 30.0,
),
],
),
),
width: double.infinity,
margin: EdgeInsets.all(20.0),
),