使用Intl包(DateFormat)时,项目无法编译 [英] Project doesn't compile when using Intl package (DateFormat)
本文介绍了使用Intl包(DateFormat)时,项目无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试导入 intl 后运行我的应用程序,但是不会工作.
I'm trying to run my app after importing intl, but it won't work.
在 pubspec.yaml
文件中,我有:
intl: ^0.15.8
经过确定,我已经通过三种方式导入了该软件包.但是似乎只使用了第一个(intl.dart):
I've imported the package in three ways after some research, just to be sure. But only the first one (intl.dart) seems to be used :
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
之后,我的错误是:
My error after flutter run
is:
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
我做错什么了吗?还是我应该报告的一揽子问题?
Am I doing something wrong? or is it a package issue that I should report?
推荐答案
我通过更改导入解决了它.而不是导入:
I solved it by changing the import. Instead of importing:
import "package:intl/intl_browser.dart";
导入以下内容:
import 'package:intl/intl_standalone.dart';
这篇关于使用Intl包(DateFormat)时,项目无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文