【发布时间】:2020-02-13 07:52:09
【问题描述】:
我试图在我的应用程序上获取我当前的日期时间,但突然间,“DateFormat”方法没有在我的应用程序上同步,即使我在顶部添加了导入库。另外,如果您将鼠标悬停在错误“DateFormat”上",它正在创建一个新类..因为它在我的应用程序上无法识别。
这是我的代码:
import 'dart:core';
import 'package:flutter/material.dart';
import 'package:intl/intl_browser.dart';
class LabelTextID extends StatelessWidget {
@override
Widget build(BuildContext context) {
var now = new DateTime.now();
var formatter = new DateFormat('yyyy-MM-dd');
String formatted = formatter.format(now);
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 130,
height: 40.0,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
"ID",
style: TextStyle(
fontSize: 26.0, color: Colors.black54),
),
),
),
Expanded(
child: Container(
height: 40.0,
decoration:new BoxDecoration(
),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
"12",
style: TextStyle(
fontSize: 26.0, color: Colors.black54),
),
),
),
),
],
),
],
);
}
}
另请参阅错误时附加的这张图片。
【问题讨论】:
-
您确定在您的 pubspec.yaml 文件中添加包并运行 flutter pub get 吗?
-
对不起,我是这个文件的新手,是的,我没有在我的依赖项中添加包..它现在可以工作了..谢谢大家..