在 image_picker 插件中拍照后黑屏

Black Screen after taking photo in image_picker plugin

我正在使用最新版本的 image_picker 插件,包括 Flutter 2.0.3 版本,而且这在真实设备(小米 Redmi Note 7)上失败了。我能看到的唯一消息是 Lost connection to我拿相机时的设备。图库作品fine.This是我的代码

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  File _image;
  final picker = ImagePicker();

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Image Picker Example'),
      ),
      body: Center(
        child: _image == null
            ? Text('No image selected.')
            : Image.file(_image),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: Icon(Icons.add_a_photo),
      ),
    );
  }
}

我已经全部添加了permissions.How可以解决这个问题吗?

添加到清单android:requestLegacyExternalStorage="true"

android {
    compileSdkVersion 29
// ....
        defaultConfig {
            targetSdkVersion 29

这应该适合您,如果想了解更多信息,请单击