無法在 iOS 模擬器上使用顫振圖像選擇器選擇圖像 (Unable to select image using flutter image picker on iOS simulator)


問題描述

無法在 iOS 模擬器上使用顫振圖像選擇器選擇圖像 (Unable to select image using flutter image picker on iOS simulator)

我正在學習如何從圖庫中選擇圖像。我已經實現了同樣的顫振圖像選擇器。但是當我嘗試在模擬器中選擇圖像時,我無法這樣做。

請幫助

Flutter Doctor

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。我已切換到 beta 頻道以擺脫一些冗長的錯誤。一切正常。只是,當我單擊圖像時,什麼也沒有發生。它沒有被選中。


參考解法

方法 1:

I've tried your code and it works on my simulator:

enter image description here

There are discussions online including this GitHub post, that this could be an Apple bug and no known workaround.

In fact, there are people in Apple Developer Forums reports this kind of issue.

(by OM KALEMαπμQμαπkγVπ.0)

參考文件

  1. Unable to select image using flutter image picker on iOS simulator (CC BY‑SA 2.5/3.0/4.0)

#flutter-packages #Flutter #flutter-dependencies






相關問題

使用顫振包有缺點嗎? (Is there a downside for using flutter packages?)

導入 Http/http.dart 包時出錯 (error in importing Http/http.dart package)

flutter pub get 卡住了 (flutter pub get is stucking)

在 Onboard Pages 上進行 Flutter 應用程序初始化? (Flutter app initialization at Onboard Pages?)

Flutter + FlutterFire 版本根據遷移指南使用 firebase_messaging 解決失敗的 firebase_remote_config (Flutter + FlutterFire version solving failed firebase_remote_config with firebase_messaging as per migration guide)

無法在 iOS 模擬器上使用顫振圖像選擇器選擇圖像 (Unable to select image using flutter image picker on iOS simulator)

Flutter Package:未壓縮的包存檔太大 (Flutter Package : Uncompressed package archive is too large)

我可以知道是否有一個顫振包可以在照片和圖紙上做標記和註釋? (May I know is there a flutter package to do markups and annotations on photos and drawings?)

使用音頻播放器包時出現顫振錯誤 (Flutter error when using audioplayer packages)

Flutter 上的 lib 中沒有包選擇 (There isn't package selection in lib on Flutter)

運行“flutter pub get”時在 google_maps_flutter 上解決 Flutter 版本失敗 (Flutter version solving failed on google_maps_flutter while running "flutter pub get")

顫振中甜甜圈圖表中的最高值弧 (Highlist highest value arc in donut chart in flutter)







留言討論