Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 仅在模拟器中工作的颤振图像选择器_Image_Flutter - Fatal编程技术网

Image 仅在模拟器中工作的颤振图像选择器

Image 仅在模拟器中工作的颤振图像选择器,image,flutter,Image,Flutter,这里需要一些帮助-相对新的颤振。我正在尝试建立一个图像选择器,允许用户从他们的图库中选择一个图像,一旦它被选中,就会显示在应用程序中。它的工作原理与emulator中的预期一样,但在我测试过的两台设备(Android API 26和28)上,用户可以打开图库,但一旦选择了图像,图像就不会保存在应用程序内屏幕上。此后,“选择图像”按钮将无响应。我在一个单独的程序中重新编写了代码,发现它工作得很好。可能是android构建依赖项或权限中的某些内容 File _image; final p

这里需要一些帮助-相对新的颤振。我正在尝试建立一个图像选择器,允许用户从他们的图库中选择一个图像,一旦它被选中,就会显示在应用程序中。它的工作原理与emulator中的预期一样,但在我测试过的两台设备(Android API 26和28)上,用户可以打开图库,但一旦选择了图像,图像就不会保存在应用程序内屏幕上。此后,“选择图像”按钮将无响应。我在一个单独的程序中重新编写了代码,发现它工作得很好。可能是android构建依赖项或权限中的某些内容

     File _image;
 final picker = ImagePicker();


 Future getImage() async {
   /* Gets the image from gallery or Camera */
   final pickedFile = await picker.getImage(source: ImageSource.gallery); //gallery
    // final pickedFile = await picker.getImage(source: ImageSource.camera); //camera
   setState(() {
     if (pickedFile != null) {
       _image = File(pickedFile.path);
     } else {
       print('No image selected.');
     }
   });
 }
容器(
边缘:边缘组。对称(水平:20,),
颜色:颜色。灰色[800],
填充:边缘组。对称(垂直:20,水平:10),
子:SingleChildScrollView(
子:列(
儿童:[
居中(
儿童:手势检测器(
onTap:()=>getImage(),
子项:(_image==null)
?容器(
身高:150,
宽度:150,
子:图标(
mdicons.cameraPlus,
尺码:40
),
装饰:盒子装饰(
边界半径:边界半径。圆形(25),
颜色:颜色。白色
),
)
:容器(
身高:180,
宽度:130,
子:Image.file(_Image),
),
),
),
试试这段代码

 Container(
            margin: EdgeInsets.symmetric(horizontal: 20,),
            color: Colors.grey[800],
            padding: EdgeInsets.symmetric(vertical: 20, horizontal: 10),
            child: SingleChildScrollView(
              child: Column(
                children:<Widget>[
                  Center(
                    child: GestureDetector(
                      onTap: () => getImage(),
                      child: (_image == null)
                       ? Container(
                        height: 150,
                        width: 150,
                        child: Icon(
                                MdiIcons.cameraPlus,
                                size: 40
                            ),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(25),
                          color: Colors.white
                        ),
                      )
                      : Container(
                        height: 180,
                        width: 130,
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                fit: BoxFit.cover,
                                image: FileImage(_image)
                              )
                            ),
                      ),
                    ),
                  ),
容器(
边缘:边缘组。对称(水平:20,),
颜色:颜色。灰色[800],
填充:边缘组。对称(垂直:20,水平:10),
子:SingleChildScrollView(
子:列(
儿童:[
居中(
儿童:手势检测器(
onTap:()=>getImage(),
子项:(_image==null)
?容器(
身高:150,
宽度:150,
子:图标(
mdicons.cameraPlus,
尺码:40
),
装饰:盒子装饰(
边界半径:边界半径。圆形(25),
颜色:颜色。白色
),
)
:容器(
身高:180,
宽度:130,
装饰:盒子装饰(
图像:装饰图像(
适合:BoxFit.cover,
image:FileImage(_image)
)
),
),
),
),

imagepicker在我的应用程序中工作正常。请尝试此代码并查看:

class _ProfileImageGetterState extends State<ProfileImageGetter> {
  File _image;
  final picker = ImagePicker();

  Future getImage() async {
    final pickedFile = await picker.getImage(source: ImageSource.gallery);

    setState(() {
      if (pickedFile != null) {
        _image = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 15.0),
      child: _image == null
          ? GestureDetector(
              onTap: getImage,
              child: Container(
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  boxShadow: [
                    BoxShadow(
                        blurRadius: 0.5, color: kGreyColor, spreadRadius: 0.5)
                  ],
                ),
                child: CircleAvatar(
                  child: Image.asset("images/edit-image-pic.png"),
                  backgroundColor: kAccentColor,
                  radius: 50.0,
                ),
              ),
            )
          : GestureDetector(
              onTap: getImage,
              child: Container(
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  boxShadow: [
                    BoxShadow(blurRadius: 3, color: kGreyColor, spreadRadius: 1)
                  ],
                ),
                child: CircleAvatar(
                  backgroundImage: FileImage(_image),
                  radius: 50.0,
                  child: Image.asset("images/edit-image-pic.png"),
                ),
              ),
            ),
    );
  }
}

class\u ProfileImageGetterState扩展状态{
文件图像;
最终选择器=图像选择器();
Future getImage()异步{
final pickedFile=wait picker.getImage(来源:ImageSource.gallery);
设置状态(){
if(pickedFile!=null){
_image=文件(pickedFile.path);
}否则{
打印('未选择图像');
}
});
}
@凌驾
小部件构建(构建上下文){
返回填充(
填充:边缘组。对称(垂直:15.0),
子项:_image==null
?手势检测器(
onTap:getImage,
子:容器(
装饰:盒子装饰(
形状:BoxShape.circle,
boxShadow:[
箱形阴影(
模糊半径:0.5,颜色:kGreyColor,扩展半径:0.5)
],
),
孩子:圆环星(
子项:Image.asset(“images/edit Image pic.png”),
背景颜色:kAccentColor,
半径:50.0,
),
),
)
:手势检测器(
onTap:getImage,
子:容器(
装饰:盒子装饰(
形状:BoxShape.circle,
boxShadow:[
BoxShadow(模糊半径:3,颜色:kGreyColor,扩展半径:1)
],
),
孩子:圆环星(
背景图片:FileImage(_image),
半径:50.0,
子项:Image.asset(“images/edit Image pic.png”),
),
),
),
);
}
}
class _ProfileImageGetterState extends State<ProfileImageGetter> {
  File _image;
  final picker = ImagePicker();

  Future getImage() async {
    final pickedFile = await picker.getImage(source: ImageSource.gallery);

    setState(() {
      if (pickedFile != null) {
        _image = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 15.0),
      child: _image == null
          ? GestureDetector(
              onTap: getImage,
              child: Container(
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  boxShadow: [
                    BoxShadow(
                        blurRadius: 0.5, color: kGreyColor, spreadRadius: 0.5)
                  ],
                ),
                child: CircleAvatar(
                  child: Image.asset("images/edit-image-pic.png"),
                  backgroundColor: kAccentColor,
                  radius: 50.0,
                ),
              ),
            )
          : GestureDetector(
              onTap: getImage,
              child: Container(
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  boxShadow: [
                    BoxShadow(blurRadius: 3, color: kGreyColor, spreadRadius: 1)
                  ],
                ),
                child: CircleAvatar(
                  backgroundImage: FileImage(_image),
                  radius: 50.0,
                  child: Image.asset("images/edit-image-pic.png"),
                ),
              ),
            ),
    );
  }
}