如何在futureBuilder中使用'toIso8601String'

时间:2019-07-10 06:48:43

标签: flutter dart flutter-web

我想用toIso8601String显示日期,但是有错误

  

未为类“ int”定义方法“ toIso8601String”。尝试   更正现有方法的名称,或定义名为   'toIso8601String'

我的朋友也完全使用了此代码,但是当我尝试该代码时出现错误..并且日期是TIMESTAMP类型

_showActivities({DateTime index}) {
return FutureBuilder(
  future: UserController.getActivityByDate(
      {"date": widget.index.toIso8601String(),
      "id" : _selectedUser
      }),
  builder: (context, snapshot) {
    return snapshot.hasData
        ? new ItemDate(list: snapshot.data)
        : Center(
            child: Center(
              child: Text(
                "No Activity",
                style: Theme.of(context).textTheme.title,
              ),
            ),
          );
  },
);

}

1 个答案:

答案 0 :(得分:1)

首先使用DateTime从您的时间戳创建一个fromMillisecondsSinceEpoch()对象:

DateTime date = DateTime.fromMillisecondsSinceEpoch(dateInTimestamp);
date.toIso8601String(); // No typing error