flutter - 使用 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
难道我做错了什么?还是我应该报告的包裹问题?
解决方案
我也遇到了这个错误。只需运行命令flutter clean
。运行此命令后,问题解决。
推荐阅读
- apache-spark - Spark结构化流过滤器并写入许多输出
- java - Spring data - “错误:当前事务被中止”:捕获 DataIntegrityViolationException 时如何回滚/提交事务?
- lua - Lua/Luajit:同时索引和命名方法?
- sql - 如何用另一个表中的列表填充列?
- python - 带线程的代理测试器
- react-native - React Native:失败:构建失败并出现异常
- php - SQL 准备语句未运行?
- python - 正则表达式抛出错误:无法初始化模板变量
- android - Android 中蓝牙 LE 设备的绑定(即“配对设备”)的最大数量是多少?
- python - Python中的列表迭代