import 'package:fast/constants.dart'; import 'package:fast/model/model.dart'; import 'package:fast/utils/api.dart'; import 'package:fast/utils/http_utils.dart'; import 'package:fast/utils/size_fit.dart'; import 'package:fast/view/component/navi_bar.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; class BalanceHistory extends StatefulWidget { int type; //0 全部 1 充值 BalanceHistory({Key? key, required this.type}) : super(key: key); @override State createState() => _BalanceHistoryState(); } class _BalanceHistoryState extends State { List list = []; bool loaded = false; @override void initState() { getList(); super.initState(); } Future getList() async { Map data = await HttpUtils.get(Api.stoneRecords, params: { 'page_num': 1, 'page_size': 100, 'trans_type': widget.type == 1 ? 'RECHARGE' : 'ALL' }); List datas = data['data']; List array = []; for (var item in datas) { array.add(HistoryBean.fromJson(item)); } setState(() { loaded = true; list = array; }); } @override Widget build(BuildContext context) { SizeFit.initialize(context); EdgeInsets safePadding = MediaQuery.of(context).padding; double screenHeight = MediaQuery.of(context).size.height; return Material( child: Container( padding: EdgeInsets.only(top: 0, bottom: safePadding.bottom), color: kBgColor, child: Stack( children: [ if (loaded && list.isEmpty) Container( width: 375.px, height: screenHeight, alignment: Alignment.center, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset('assets/images/no_content.png',width: 88.px,height: 80.px,), SizedBox(height: 16.px,), Text(widget.type==0?'您还没有逆龄石相关记录':'您还没有逆龄石充值记录',style: TextStyle(color:const Color(0x66C4CCDA),fontSize: 14.px,fontWeight: FontWeight.bold ),) ], ), ), SizedBox( height: screenHeight, child: SingleChildScrollView( child: Column(children: [ SizedBox( height: 40.px + safePadding.top, ), ...List.generate(list.length, (i) { return item(list[i]); }) ]))), NaviBar( title: widget.type == 0 ? '逆龄石记录' : '充值记录', closeCallback: () { Get.back(); }) ], ))); } Widget item(HistoryBean bean) { return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 12.px, ), Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( width: 24.px, ), Container( margin: EdgeInsets.only(bottom: 2.px), child: Text( bean.stone > 0 ? '+' + bean.stone.toString() : bean.stone.toString(), style: TextStyle( color: kThemeColor, fontFamily: 'Exo2', fontWeight: FontWeight.w600, fontSize: 16.px), ), ), SizedBox( width: 6.px, ), Image.asset( 'assets/images/stone.png', width: 16.px, height: 16.px, ), SizedBox( width: 12.px, ), Text( formatTime(bean.dateTime!), style: TextStyle(color: const Color(0x80C4CCDA), fontSize: 12.px), ) ], ), Container( margin: EdgeInsets.only(left: 24.px, top: 9.px), child: Text( bean.description, textAlign: TextAlign.left, style: TextStyle( color: Colors.white, fontSize: 14.px, ), ), ), Container( margin: EdgeInsets.only(top: 12.px, left: 24.px), height: 1.px, width: 328.px, color: const Color(0x1AC4CCDA), ) ], ); } formatTime(DateTime dateTime) { DateTime now = DateTime.now(); int minutes = (now.millisecondsSinceEpoch ~/ 1000 - dateTime.millisecondsSinceEpoch ~/ 1000) ~/ 60; if (minutes < 1) { return '刚刚'; } else if (minutes <= 59) { return minutes.toString() + '分钟前'; } else if (minutes <= 60 * 24 - 1) { return (minutes ~/ 60).toString() + '小时前'; } else if (minutes <= 60 * 24 * 3 - 1) { return (minutes ~/ (60 * 24)).toString() + '天前'; } return dateTime.year.toString() + '-' + dateTime.month.toString().padLeft(2, "0") + '-' + dateTime.day.toString().padLeft(2, "0"); } }