【问题标题】:Flutter Build failure: Not found: 'dart:html' import 'dart:html' http-0.12.2Flutter 构建失败:未找到:'dart:html' import 'dart:html' http-0.12.2
【发布时间】:2020-11-24 04:34:02
【问题描述】:

不知道如何进入编译错误:

Compiler message:                                                       
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:6:8: Error: Not found: 'dart:html'
import 'dart:html';                                                     
       ^                                                                
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:34:18: Error: 'HttpRequest' isn't a type.
  final _xhrs = <HttpRequest>{};                                        
                 ^^^^^^^^^^^                                            
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:58:34: Error: 'Blob' isn't a type.
      var blob = xhr.response as Blob ?? Blob([]);                      
                                 ^^^^                                   
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:46:15: Error: The method 'HttpRequest' isn't defined for the class 'BrowserClient'.
 - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart').
Try correcting the name to the name of an existing method, or defining a method named 'HttpRequest'.
    var xhr = HttpRequest();                                            
              ^^^^^^^^^^^                                               
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:58:42: Error: The method 'Blob' isn't defined for the class 'BrowserClient'.
 - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart').
Try correcting the name to the name of an existing method, or defining a method named 'Blob'.
      var blob = xhr.response as Blob ?? Blob([]);                      
                                         ^^^^                           
../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart:59:20: Error: The method 'FileReader' isn't defined for the class 'BrowserClient'.
 - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/src/browser_client.dart').
Try correcting the name to the name of an existing method, or defining a method named 'FileReader'.
      var reader = FileReader();                                        
                   ^^^^^^^^^^   

【问题讨论】:

    标签: java android flutter flutter-dependencies


    【解决方案1】:

    对于遇到此问题的任何人, 当您导入一些属于 web 的包时,就会发生这种情况。 就我而言,我导入了这个,

    import 'package:dio/browser_imp.dart';
    

    因此发生了构建失败。只需删除导入即可。

    【讨论】:

      【解决方案2】:

      尝试清理包缓存。

      pub cache repair
      

      flutter clean 
      

      【讨论】:

      • 您好 Anirudh,我执行了这两个命令,但没有运气。另外,我还有另一个颤振项目,我在其中使用 http: 0.12.1 并且我没有看到任何错误。更多线索说明为什么这个特定项目会收到错误,即太缺少 dart 文件。
      • 导入错误文件是我的错误。删除了 browser_client.dart 应该没有被导入。
      猜你喜欢
      • 2020-12-26
      • 1970-01-01
      • 2022-09-29
      • 2020-01-18
      • 1970-01-01
      • 2021-09-20
      • 2021-10-30
      • 2020-04-22
      • 2012-11-04
      相关资源
      最近更新 更多