有没有办法在Flitter中的LIstView.Builder中将历元时间戳格式化为人类日期格式?

有没有办法在Flitter中的LIstView.Builder中将历元时间戳格式化为人类日期格式?,listview,flutter,dart,stripe-payments,epoch,Listview,Flutter,Dart,Stripe Payments,Epoch,我在我的应用程序中使用条带支付。我需要显示事务列表和创建事务的日期。为此,我调用了一个API。但API响应中的日期格式为历元时间戳。我必须将其转换为人类可读的日期格式。为此,我正在使用flutter中的插件时间格式化程序。 是否有办法将时间戳转换为日期格式。我已经附上下面的代码。请告诉我一个解决办法 import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth

我在我的应用程序中使用条带支付。我需要显示事务列表和创建事务的日期。为此,我调用了一个API。但API响应中的日期格式为历元时间戳。我必须将其转换为人类可读的日期格式。为此,我正在使用flutter中的插件时间格式化程序。 是否有办法将时间戳转换为日期格式。我已经附上下面的代码。请告诉我一个解决办法


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:time_formatter/time_formatter.dart';
import 'package:rewahub/widgets/comp_search.dart';
import 'package:rewahub/widgets/loading.dart';
import 'package:rewahub/widgets/styles.dart';

class TransactionsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: new PreferredSize(
        preferredSize: const Size.fromHeight(90.0),
        child: new AppBar(
          // elevation: 0.0,
          centerTitle: false,
          bottom: new PreferredSize(
            child: Column(
              children: <Widget>[
                new Row(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    Text(
                      "8956",
                      textAlign: TextAlign.left,
                      style: TextStyle(color: Colors.white, fontSize: 18.0),
                    ),
                    Image.asset(
                      'assets/images/rewahub_icon.png',
                      height: 50.0,
                    ),
                    Text(
                      "RS 434.25",
                      style: TextStyle(color: Colors.white, fontSize: 18.0),
                    ),
                  ],
                ),
              ],
            ),
          ),
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: grad,
            ),
          ),
        ),
      ),
      body: Column(
        children: <Widget>[
          Container(
            decoration: BoxDecoration(
              gradient: grad,
            ),
            height: 100.0,
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.fromLTRB(50, 10, 50, 10),
                ),
                CompSearch(),
                Padding(
                  padding: EdgeInsets.only(left: 30.0),
                ),
                Expanded(
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      "        Tap the Items for Details",
                      style: TextStyle(
                        fontSize: 15.0,
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
          Expanded(
            child: TransactionBody(),
          )
        ],
      ),
    );
  }
}

class TransactionBody extends StatefulWidget {
  @override
  _TransactionBodyState createState() => _TransactionBodyState();
}

class _TransactionBodyState extends State<TransactionBody> {
  var loading;
  List chargedata;
  Map data;

  final Map<String, String> authdata = {
    'Authorization': 'Bearer sk_test_91jzKPJNlDAb9oviflmUZ7kT00DU51CVeW',
  };
  chargelist() async {
    FirebaseUser userData = await FirebaseAuth.instance.currentUser();
    DocumentReference documentReference = Firestore.instance
        .collection('customer')
        .document(userData.uid)
        .collection('customerprofile')
        .document(userData.uid);
    documentReference.get().then((snaps) async {
      var stripeid;
      stripeid = snaps.data['id'];
      await new Future.delayed(const Duration(seconds: 1));

      await http
          .get("https://api.stripe.com/v1/charges?customer=" + stripeid + "",
              headers: authdata)
          .then((http.Response response) {
        data = json.decode(response.body);
      });
      chargedata = data["data"];
      setState(() {
        loading = false;
      });
      print(chargedata);
    });
  }

  @override
  void initState() {
    chargelist();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6.0),
        border: Border.all(color: Colors.white),
      ),
      child: loading == false
          ? new ListView.builder(
              itemCount: chargedata == null ? 0 : chargedata.length,
              itemBuilder: (BuildContext context, int index) {
                return ListTile(
                  contentPadding: EdgeInsets.only(top: 10, bottom: 10),
                  title: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      new Text(
                        "${chargedata[index]["description"]}",
                        style: TextStyle(fontSize: 20, color: Colors.black87),
                      ),
                    ],
                  ),
                  subtitle: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      new SizedBox(height: 6.0),
                      new Text(
                        " Date Created",
                        style: TextStyle(fontSize: 15, color: Colors.black54),
                      ),
                      new SizedBox(height: 4.0,),
                      timestamp = formatTime(chargedata[index]["created"]), 

// i am getting error here , while tried to convert it to human timestamp e:The element type 'String' can't be assigned to the list type 'Widget'.dart(list_element_type_not_assignable)//

                      new Text(
                        timestamp.toString(),
                        style: TextStyle(
                          fontSize: 15,
                          color: reddish,
                        ),
                      ),
                    ],
                  ),
                  trailing: Text(
                    "\$ ${chargedata[index]["amount"] / 100}",
                    style: TextStyle(
                      fontSize: 35,
                      color: Colors.blueGrey,
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                  dense: false,
                  onTap: () {
                    print('Notifications');
                  },
                );
              })
          : LoadingPage(),
    );
  }
}

导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:firebase_auth/firebase_auth.dart”;
进口“包装:颤振/材料.省道”;
将“package:http/http.dart”导入为http;
导入“package:time_formatter/time_formatter.dart”;
导入“package:rewahub/widgets/comp_search.dart”;
导入“package:rewahub/widgets/loading.dart”;
导入“package:rewahub/widgets/styles.dart”;
类TransactionPage扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
resizeToAvoidBottomPadding:false,
appBar:新的PreferredSize(
首选尺寸:从高度(90.0)算起的常数尺寸,
孩子:新的AppBar(
//标高:0.0,
标题:错误,
底部:新的首选尺寸(
子:列(
儿童:[
新行(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
正文(
"8956",
textAlign:textAlign.left,
样式:TextStyle(颜色:Colors.white,fontSize:18.0),
),
影像资产(
“assets/images/rewahub_icon.png”,
身高:50.0,
),
正文(
“RS 434.25”,
样式:TextStyle(颜色:Colors.white,fontSize:18.0),
),
],
),
],
),
),
flexibleSpace:容器(
装饰:盒子装饰(
梯度:梯度,
),
),
),
),
正文:专栏(
儿童:[
容器(
装饰:盒子装饰(
梯度:梯度,
),
高度:100.0,
子:列(
儿童:[
填充物(
填充:从LTRB(50,10,50,10)开始的边缘设置,
),
CompSearch(),
填充物(
填充:仅限边缘设置(左:30.0),
),
扩大(
子对象:对齐(
对齐:alignment.centerLeft,
子:文本(
“点击项目了解详细信息”,
样式:TextStyle(
字体大小:15.0,
颜色:颜色,白色,
),
),
),
)
],
),
),
扩大(
子项:TransactionBody(),
)
],
),
);
}
}
类TransactionBody扩展StatefulWidget{
@凌驾
_TransactionBodyState createState();
}
类_TransactionBodyState扩展状态{
无功负荷;
列出收费数据;
地图数据;
最终地图授权数据={
“授权”:“承载sk_测试”91jzKPJNlDAb9oviflmUZ7kT00DU51CVeW”,
};
chargelist()异步{
FirebaseUser userData=等待FirebaseAuth.instance.currentUser();
DocumentReference=Firestore.instance
.收款(“客户”)
.document(userData.uid)
.collection('customerprofile')
.document(userData.uid);
documentReference.get()。然后((快照)异步{
var-stripeid;
stripeid=snaps.data['id'];
等待新的未来。延迟(持续时间(秒:1));
等待http
.get(“https://api.stripe.com/v1/charges?customer=“+stripeid+”,
标题:authdata)
.然后((http.Response){
data=json.decode(response.body);
});
chargedata=数据[“数据”];
设置状态(){
加载=假;
});
打印(收费数据);
});
}
@凌驾
void initState(){
收费表();
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回容器(
填充:新边集。对称(垂直:10.0,水平:25.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(6.0),
边框:边框。全部(颜色:颜色。白色),
),
子项:加载==false
?新建ListView.builder(
itemCount:chargedata==null?0:chargedata.length,
itemBuilder:(构建上下文,int索引){
返回列表块(
contentPadding:仅限边集(顶部:10,底部:10),
标题:新专栏(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
新文本(
“${chargedata[索引][“说明”]}”,
样式:TextStyle(字体大小:20,颜色:Colors.black87),
),
],
),
副标题:新专栏(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
新尺寸盒子(高度:6.0),
新文本(
“创建日期”,
样式:TextStyle(字体大小:15,颜色:Colors.black54),
),
新尺寸盒子(高度:4.0,),
提姆