为什么我无法显示相机中的图像?

问题描述 投票:0回答:1

我不知道为什么我的代码不显示相机的图像。我尝试了这段代码,但var不是空的,但是没有在容器中显示图像。我也没有任何错误。感谢您的帮助。

class _MyAppState extends State {
  File _imagen;
  Future getImagen() async {
    var imagen = await ImagePicker.pickImage(source: ImageSource.camera);

    setState(() {
      _imagen = imagen;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('picker'),
        ),

        body: Container(
          child: Center(
            child: _imagen == null
                ? new Text('no hay imagen')
                : new Image.file(_imagen),
          ),
        ),

        floatingActionButton: new FloatingActionButton(
          onPressed: getImagen,
          child: Icon(Icons.camera),
        ),
      ),
    );
  }
}
image camera flutter show
1个回答
0
投票

将图像选择器更改为最新image_picker: ^0.6.0+10

© www.soinside.com 2019 - 2024. All rights reserved.