簡體   English   中英

在顫振中使用圖像選擇器和 web_image_picker 時出錯

[英]Error while using image picker and web_image_picker in flutter

我遇到了一個問題,我正在使用圖像選擇器和網絡圖像選擇器

事情在網絡上運行良好,但是當我嘗試在 android 中運行它時,由於網絡圖像選擇器而出現一些錯誤

找不到錯誤 dart:html Not found dart:js 和所有

在這里我使用圖像選擇器

           Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    InkWell(
                      onTap: () async {
                        await getImage();
                      },
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.grey[200],
                          borderRadius: BorderRadius.circular(8),
                          border: Border.all(
                            color: Colors.grey,
                            width: 0.5,
                          ),
                          // boxShadow: const [
                          //   BoxShadow(
                          //     color: Colors.grey,
                          //     blurRadius: 2,
                          //     spreadRadius: 1,
                          //   ),
                          // ],
                        ),
                        // padding: const EdgeInsets.all(16),
                        height: MediaQuery.of(context).size.width * 0.4,
                        width: MediaQuery.of(context).size.width * 0.4,
                        child: _image != null
                            ? kIsWeb
                                ? Image.memory(
                                    _image,
                                    fit: BoxFit.cover,
                                  )
                                : Image.file(
                                    _image,
                                    fit: BoxFit.cover,
                                  )
                            : Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Icon(
                                    Icons.photo,
                                    size: 40,
                                    color: Colors.grey[600],
                                  ),
                                  const SizedBox(height: 8),
                                  Text(
                                    'Upload Your Image',
                                    style: TextStyle(
                                        fontSize: 18,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.grey[600]),
                                  ),
                                ],
                              ),
                      ),
                    ),
                   
                  ],
            ),

它是 getImage() 方法

getImage() async {
    if (kIsWeb) {
      Uint8List? image = await ImagePickerWeb.getImageAsBytes();
      setState(() {
        _image = image;
      });
      print('web');
    } else {
      XFile? image = await imagePicker.pickImage(source: ImageSource.gallery);
      setState(() {
        _image = file.File(image!.path);
      });
    }
  }

這是完整的錯誤消息

Launching lib/main.dart on M2004J19C in debug mode...
Invalid depfile: /home/themahi19/Jfamosdelivery/JFAMOSDelivery/jfamosdelivery/.dart_tool/flutter_build/c0ec4bfe11c84de97b0557ad244bec17/kernel_snapshot.d
Invalid depfile: /home/themahi19/Jfamosdelivery/JFAMOSDelivery/jfamosdelivery/.dart_tool/flutter_build/c0ec4bfe11c84de97b0557ad244bec17/kernel_snapshot.d
: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^

: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
: Error: Not found: 'dart:html'
import 'dart:html';
       ^

: Error: Not found: 'dart:js'
export 'dart:js' show allowInterop, allowInteropCaptureThis;
^

: Error: Type 'html.File' not found.
  static Future<html.File?> _pickFile(String type) async {
                ^^^^^^^^^
: Error: Type 'html.File' not found.
  Future<List<html.File>?> _pickMultiFiles(String type) async {
              ^^^^^^^^^

: Error: Type 'html.File' not found.
  static Future<html.File?> getImageAsFile() {
                ^^^^^^^^^
: Error: Type 'html.File' not found.
  static Future<List<html.File>?> getMultiImagesAsFile() {
                     ^^^^^^^^^
: Error: Type 'html.File' not found.
  static Future<html.File?> getVideoAsFile() {
                ^^^^^^^^^
: Error: Type 'html.File' not found.

extension FileModifier on html.File {
                          ^^^^^^^^^
: Error: Type 'html.EventListener' not found.
  external ui.VoidCallback addPopStateListener(html.EventListener fn);
                                               ^^^^^^^^^^^^^^^^^^
: Error: Type 'html.Location' not found.
  html.Location get _location => html.window.location;
  ^^^^^^^^^^^^^
: Error: Type 'html.History' not found.
  html.History get _history => html.window.history;
  ^^^^^^^^^^^^

: Error: Type 'html.EventListener' not found.
  void addPopStateListener(html.EventListener fn) {
                           ^^^^^^^^^^^^^^^^^^
: Error: Type 'html.EventListener' not found.
  void removePopStateListener(html.EventListener fn) {
                              ^^^^^^^^^^^^^^^^^^
: Error: Type 'AnchorElement' not found.
final AnchorElement _urlParsingNode = AnchorElement();
      ^^^^^^^^^^^^^
: Error: Type 'Element' not found.
final Element? _baseElement = document.querySelector('base');
      ^^^^^^^

: Error: 'File' isn't a type.
    final completer = Completer<List<html.File>?>();

                                          ^^^^
: Error: Method not found: 'FileUploadInputElement'.
    final input = html.FileUploadInputElement() as html.InputElement;
                       ^^^^^^^^^^^^^^^^^^^^^^
: Error: 'InputElement' isn't a type.
    final input = html.FileUploadInputElement() as html.InputElement;
                                                        ^^^^^^^^^^^^
: Error: 'Event' isn't a type.
    void changeEventListener(html.Event e) {
                                  ^^^^^

: Error: 'File' isn't a type.
      final resultFuture = files.map<Future<html.File>>((file) async {
                                                 ^^^^
: Error: Method not found: 'FileReader'.
        final reader = html.FileReader();

                            ^^^^^^^^^^
: Error: 'Event' isn't a type.
    void cancelledEventListener(html.Event e) {
                                     ^^^^^
: Error: Undefined name 'window'.
      html.window.removeEventListener('focus', cancelledEventListener);
           ^^^^^^
: Error: Undefined name 'window'.
    html.window.addEventListener('focus', cancelledEventListener);
         ^^^^^^
: Error: Undefined name 'document'.
    html.document.body!.append(input);
         ^^^^^^^^
: Error: 'File' isn't a type.
    final completer = Completer<List<html.File>?>();
                                          ^^^^
: Error: Method not found: 'FileUploadInputElement'.
    final input = html.FileUploadInputElement();
                       ^^^^^^^^^^^^^^^^^^^^^^
: Error: 'Event' isn't a type.
    void changeEventListener(html.Event e) {
                                  ^^^^^
: Error: 'File' isn't a type.
      final resultsFutures = files.map<Future<html.File>>((file) async {
                                                   ^^^^
: Error: Method not found: 'FileReader'.
        final reader = html.FileReader();
                            ^^^^^^^^^^
: Error: 'Event' isn't a type.
    void cancelledEventListener(html.Event e) {
                                     ^^^^^
: Error: Undefined name 'window'.
      html.window.removeEventListener('focus', cancelledEventListener);
           ^^^^^^
: Error: Undefined name 'window'.

    html.window.addEventListener('focus', cancelledEventListener);
         ^^^^^^
: Error: Undefined name 'document'.
    html.document.body!.append(input);
         ^^^^^^^^
: Error: Method not found: 'FileReader'.
    final reader = html.FileReader();
                        ^^^^^^^^^^
: Error: Method not found: 'FileUploadInputElement'.
    final input = html.FileUploadInputElement();
                       ^^^^^^^^^^^^^^^^^^^^^^
: Error: Undefined name 'document'.
    html.document.body!.append(input);
         ^^^^^^^^
: Error: Method not found: 'FileReader'.
    final reader = html.FileReader();
                        ^^^^^^^^^^
: Error: Method not found: 'FileUploadInputElement'.
    final input = html.FileUploadInputElement();
                       ^^^^^^^^^^^^^^^^^^^^^^
: Error: Undefined name 'document'.
    html.document.body!.append(input);
         ^^^^^^^^
: Error: Method not found: 'FileReader'.

    final reader = html.FileReader();
                        ^^^^^^^^^^
: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addPostFrameCallback((_) {
                   ^

: Error: Method not found: 'allowInterop'.
    getPath: allowInterop(strategy.getPath),
             ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.
    getState: allowInterop(strategy.getState),
              ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.
    addPopStateListener: allowInterop(strategy.addPopStateListener),
                         ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.
    prepareExternalUrl: allowInterop(strategy.prepareExternalUrl),
                        ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.
    pushState: allowInterop(strategy.pushState),
               ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.
    replaceState: allowInterop(strategy.replaceState),
                  ^^^^^^^^^^^^
: Error: Method not found: 'allowInterop'.

    go: allowInterop(strategy.go),
        ^^^^^^^^^^^^
: Error: 'EventListener' isn't a type.

  external ui.VoidCallback addPopStateListener(html.EventListener fn);
                                                    ^^^^^^^^^^^^^
: Error: Undefined name 'window'.
  html.Location get _location => html.window.location;
                                      ^^^^^^
: Error: Undefined name 'window'.
  html.History get _history => html.window.history;
                                    ^^^^^^
: Error: 'EventListener' isn't a type.
  void addPopStateListener(html.EventListener fn) {
                                ^^^^^^^^^^^^^
: Error: Undefined name 'window'.
    html.window.addEventListener('popstate', fn);
         ^^^^^^

: Error: 'EventListener' isn't a type.
  void removePopStateListener(html.EventListener fn) {
                                   ^^^^^^^^^^^^^
: Error: Undefined name 'window'.
    html.window.removeEventListener('popstate', fn);
         ^^^^^^

: Error: 'AnchorElement' isn't a type.
final AnchorElement _urlParsingNode = AnchorElement();
      ^^^^^^^^^^^^^

: Error: Method not found: 'AnchorElement'.
final AnchorElement _urlParsingNode = AnchorElement();
                                      ^^^^^^^^^^^^^
: Error: 'Element' isn't a type.
final Element? _baseElement = document.querySelector('base');
      ^^^^^^^
: Error: Undefined name 'document'.
final Element? _baseElement = document.querySelector('base');
                              ^^^^^^^^
: Error: Method not found: 'webOnlySetPluginHandler'.

    ui.webOnlySetPluginHandler(handleFrameworkMessage);
       ^^^^^^^^^^^^^^^^^^^^^^^

Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)

#1      asFileUri (package:vm/kernel_front_end.dart:652:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:792:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (file:///b/s/w/ir/cache/builder/sdk/pkg/frontend_server/lib/frontend_server.dart:615:9)
<asynchronous suspension>
#4      starter (file:///b/s/w/ir/cache/builder/sdk/pkg/frontend_server/lib/frontend_server.dart:1433:12)
<asynchronous suspension>
#5      main (file:///b/s/w/ir/cache/builder/sdk/pkg/frontend_server/bin/frontend_server_starter.dart:10:14)
<asynchronous suspension>

FAILURE: Build failed with an exception.

* Where:
Script '/home/themahi19/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1156

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/themahi19/snap/flutter/common/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org
BUILD FAILED in 34s
Exception: Gradle task assembleDebug failed with exit code 1
Exited

在文件中包含 Web導入將在移動設備上運行期間引發錯誤。 要解決此問題,您可以使用條件導入或創建兩個文件( class/widget ),一個用於移動設備,另一個用於網絡,並根據平台選擇使用哪一個。 有關更多詳細信息,請查看此帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM