首页 > 解决方案 > 选择的图像不会在应用程序的发布版本中呈现

问题描述

我使用颤振开发了一个应用程序,在应用程序的调试版本上一切正常,但是当我使用发布版本进行测试并尝试从相机或画廊添加图像时,图像不会显示在Image.file Widget我是用来渲染它。但同样的过程在调试中运行良好。/android/app/src/main/AndroidManifest我已经为文件添加了权限

<uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

但似乎没有任何效果。

  Widget cameraPhoto() {
    return Consumer<HouseHoldViewModel>(builder: (context, vm, _) {
     
      return vm.savedImage.file != null && vm.savedImage.file.toString().isNotEmpty
          ? ClipOval(
    child:
         Image.file(
      vm.savedImage.file,
      height: 86,
      width: 86,
      fit: BoxFit.fill,
    ),
  ): Container(
                  alignment: Alignment.center,
                  width: 100,
                  height: 100,
                  decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      image: DecorationImage(
                          fit: BoxFit.cover,
                          image: vm.pictureUrl != null &&
                                  vm.pictureUrl.isNotEmpty
                              ? CachedNetworkImageProvider(vm.pictureUrl)
                              : ExactAssetImage('assets/profile_holder.png'))))
           ;
    });
  }

这是在我使用选择图像后应该处理图像显示的方法Image picker

void _bottomModal() {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Container(
            padding: EdgeInsets.all(6),
            height: 100,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Consumer<HouseHoldViewModel>(
                    builder: (context, vm, _) => GestureDetector(
                          onTap: () => _pickImage(vm, ImageSource.camera),
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.photo_camera),
                              SizedBox(
                                width: 10,
                              ),
                              Text(S.of(context).takeAPicture)
                            ],
                          ),
                        )),
                SizedBox(
                  height: 20,
                ),
                Consumer<HouseHoldViewModel>(
                    builder: (context, vm, _) => GestureDetector(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.photo_library),
                              SizedBox(
                                width: 10,
                              ),
                              Text(S.of(context).chooseFromGallery)
                            ],
                          ),
                          onTap: () => _pickImage(vm, ImageSource.gallery),
                        ))
              ],
            ),
          );
        });
  }

  void _pickImage(HouseHoldViewModel vm, ImageSource source) async {
    var selected = await ImagePicker.pickImage(source: source);
    vm.setSavedImage = selected;
    Navigator.pop(context);
  }

由于它在我的应用程序的调试版本上运行良好,为什么该版本无法正常工作。请帮我。谢谢你。

标签: flutterdartrelease

解决方案


推荐阅读