如何在 futureBuilder 中使用 'toIso8601String'

how to use 'toIso8601String' in futureBuilder

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

The method 'toIso8601String' isn't defined for the class 'int'. Try correcting the name of an existing method, or defining a method named '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,
              ),
            ),
          );
  },
);

}

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

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