首页 > 解决方案 > 使用 Intl 包 (DateFormat) 时项目无法编译

问题描述

我试图在导入intl后运行我的应用程序,但它不起作用。

pubspec.yaml我的文件中:

intl: ^0.15.8

经过一些研究,我已经以三种方式导入了包,以确保。但似乎只使用了第一个(intl.dart):

import "package:intl/intl.dart";
import "package:intl/intl_browser.dart"; //unused import
import "package:intl/intl_standalone.dart"; //unused import

我这样使用它:

DateFormat("dd-MM-yyyy").format(_chosenDate)

我的错误flutter run是:

Resolving dependencies...                                           2,3s
                                                                        
Compiler message:                                                       
file:///Users/mydomus/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.15.8/lib/intl_browser.dart:25:48: Error: Getter not found: 'window'.
  Intl.systemLocale = Intl.canonicalizedLocale(window.navigator.language);
                                               ^^^^^^                   
file:///Users/mydomus/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.15.8/lib/intl_browser.dart:13:8: Error: Not found: 'dart:html'
import "dart:html";                                                     
       ^                                                                
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:33:7)
#1      asFileUri (package:vm/kernel_front_end.dart:589:37)             
<asynchronous suspension>                                               
#2      FrontendCompiler._outputDependenciesDelta (package:vm/frontend_server.dart:391:39)
<asynchronous suspension>                                               
#3      FrontendCompiler.compile (package:vm/frontend_server.dart:365:13)
<asynchronous suspension>                                               
#4      _FlutterFrontendCompiler.compile (package:frontend_server/server.dart:31:22)
<asynchronous suspension>                                               
#5      starter (package:frontend_server/server.dart:133:27)            
<asynchronous suspension>                                               
#6      main (file:///b/s/w/ir/k/src/flutter/frontend_server/bin/starter.dart:8:30)
<asynchronous suspension>                                               
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:298:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
                                                                        
Compiler failed on /Users/mydomus/Desktop/meriem/flutter/mydomus_edl/lib/main.dart

难道我做错了什么?还是我应该报告的包裹问题?

标签: flutterdart

解决方案


我也遇到了这个错误。只需运行命令flutter clean。运行此命令后,问题解决。


推荐阅读