颤振图像选择器无法工作并且应用程序崩溃,调试时没有错误

Mat*_*ves 11 flutter imagepicker

我目前正在使用这些版本: flutter : 2.16.0 image_picker : ^0.8.4+7

图像选择器不工作。运行应用程序后,当我单击按钮激活功能时pickImage,运行突然停止,应用程序崩溃并停止。在调试时,我收到的唯一消息是:

与设备的连接丢失。

这是代码:

import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:hipocampus_editors/widgets/textformfield_widget.dart';
import 'package:image_picker/image_picker.dart';

class AddSystemPage extends StatefulWidget {
  const AddSystemPage({Key? key}) : super(key: key);

  @override
  _AddSystemPageState createState() => _AddSystemPageState();
}

class _AddSystemPageState extends State<AddSystemPage> {
  final _formKey = GlobalKey<FormState>();
File? image1;

  Future pickImage() async{
    
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if (image == null)  return;
final imageTemporary = File(image.path);
setState(() {
  image1 = imageTemporary;
});

    } 
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
      child: Scaffold(
        appBar: AppBar(title: const Text('System',),),
        
        body: SafeArea(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 5),
            child: Form(
              key: _formKey,
              child: Container(
                width: MediaQuery.of(context).size.width,
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: SingleChildScrollView(
                    child: Column(
                  children: [
                    
                    ElevatedButton(onPressed: (){
                      pickImage();
                                          }, child: Text('Select image'))
                    
                  ],
                )),
              ),
            ),
          ),
        ),
      ),
    );
    }
    }
Run Code Online (Sandbox Code Playgroud)

Mat*_*ves 16

将其添加到 iOS>runner>Info.plist

<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access to photo library</string>
Run Code Online (Sandbox Code Playgroud)