【问题标题】:importing issue: DateFormat on flutter导入问题:颤动中的日期格式
【发布时间】: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 吗?
  • 对不起,我是这个文件的新手,是的,我没有在我的依赖项中添加包..它现在可以工作了..谢谢大家..

标签: flutter dart


【解决方案1】:

要使用DateFormat,你应该使用这个package

import 'package:intl/intl.dart';

不要忘记在pubspec.yaml中添加intl: ^0.16.1

【讨论】:

  • 对我不起作用,没有显示“package:intl****”的智能感知
  • 确保在pubspec.yaml 中添加intl: ^0.16.1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
  • 2011-09-20
相关资源
最近更新 更多