无法在 iOS 模拟器上使用颤振图像选择器选择图像

时间:2021-02-08 14:40:26

标签: flutter flutter-dependencies flutter-packages

我正在学习如何从图库中选择图像。我已经为此实现了颤振图像选择器。但是当我尝试在模拟器中选择图像时,我无法这样做。

请帮忙

颤振医生

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.26.0-17.3.pre, on macOS 11.1 20C69 darwin-arm, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)

• No issues found!

我的代码

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

void main() {
  runApp(MaterialApp(
    home: Play(),
    // theme: ThemeData.dark(),
  ));
}

class Play extends StatefulWidget {
  @override
  _PlayState createState() => _PlayState();
}

class _PlayState extends State<Play> {
  File _file;

  ImagePicker _picker = ImagePicker();

  PickedFile _pickedFile;

  Future _getImageFromGallery() async {
    print("Getting Image from Gallery.");
    _pickedFile = await _picker.getImage(source: ImageSource.gallery);
    print(_pickedFile.path);
    setState(() {
      _file = File(_pickedFile.path);
    });
  }

  Future _getImageFromCamera() async {
    print("Getting Image from Camera.");
    _pickedFile = await _picker.getImage(source: ImageSource.camera);
    setState(() {
      _file = File(_pickedFile.path);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Play"),
      ),
      body: Column(
        children: [
          Center(
            child: ElevatedButton(
                onLongPress: _getImageFromCamera,
                onPressed: _getImageFromGallery,
                child: Text("Get Image")),
          ),
          _file != null
              ? Image.file(
                  _file,
                  height: 200,
                )
              : Icon(
                  Icons.image,
                  size: 100,
                ),
        ],
      ),
    );
  }
}

我使用的是 M1 Mac air。我已切换到测试版频道以摆脱一些冗长的错误。 一切正常。只是,当我单击图像时,什么也没有发生。它没有被选中。

0 个答案:

没有答案