import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:makemoney/api/gold_corn_api.dart';
|
import 'package:makemoney/model/gold_core_model.dart';
|
import 'package:makemoney/model/user/extract_money_model.dart';
|
import 'package:makemoney/ui/widget/button.dart';
|
import 'package:makemoney/ui/widget/common_ui.dart';
|
import 'package:makemoney/ui/widget/dialog.dart';
|
import 'package:makemoney/ui/widget/refresh_listview.dart';
|
import 'package:makemoney/utils/ui_constant.dart';
|
import 'package:makemoney/utils/ui_utils.dart';
|
|
import '../../ui/widget/nav.dart';
|
|
class GoldCornPage extends StatefulWidget {
|
GoldCornPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_GoldCornPageState createState() => _GoldCornPageState();
|
}
|
|
class _GoldCornPageState extends State<GoldCornPage>
|
with SingleTickerProviderStateMixin {
|
TabController? _tabController;
|
|
int _balance = 0;
|
int _exchanging = 0;
|
|
int selectedIndex = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
_tabController = TabController(length: 2, vsync: this);
|
_tabController!.index = 0;
|
_getGoldCornInfo();
|
}
|
|
void _getGoldCornInfo() async {
|
Map<String, dynamic>? result =
|
await GoldCornApiUtil.getGoldCornInfo(context);
|
if (result == null) {
|
return;
|
}
|
if (result["code"] != 0) {
|
ToastUtil.toast(result["msg"], context);
|
return;
|
}
|
setState(() {
|
_balance = result["data"]["balance"];
|
_exchanging = result["data"]["exchanging"];
|
});
|
}
|
|
BoxDecoration getItemDecoration(Color bgColor, Color shadowColor) {
|
return BoxDecoration(
|
borderRadius: const BorderRadius.all(Radius.elliptical(10, 10)),
|
color: bgColor,
|
boxShadow: [
|
BoxShadow(
|
color: shadowColor,
|
blurRadius: 2.0,
|
offset: const Offset(0.0, 5.0), //阴影y轴偏移量
|
spreadRadius: 1 //阴影扩散程度
|
)
|
]);
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: const Color(0xFFF0F0F0),
|
body: Column(
|
children: [
|
TopNavBar(title: "金币"),
|
Expanded(
|
child: Container(
|
padding: const EdgeInsets.only(left: 10, right: 10),
|
child: Column(children: [
|
const SizedBox(
|
height: 10,
|
),
|
//余额视图
|
AspectRatio(
|
aspectRatio: 3.3875,
|
child: Stack(
|
alignment: Alignment.bottomCenter,
|
children: [
|
Image.asset(
|
"assets/imgs/mine/ic_gold_corn_bg.png"),
|
Container(
|
margin: EdgeInsets.only(
|
left: 20, top: 14, bottom: 10),
|
child: Column(
|
crossAxisAlignment:
|
CrossAxisAlignment.start,
|
mainAxisSize: MainAxisSize.min,
|
children: [
|
const Text(
|
"金币",
|
style: TextStyle(
|
color: Colors.white,
|
fontSize: 12),
|
),
|
const SizedBox(
|
height: 5,
|
),
|
Text.rich(TextSpan(
|
text: "$_balance",
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 30),
|
children: const [
|
TextSpan(
|
text: "个",
|
style: TextStyle(
|
color: Colors.white,
|
fontSize: 15))
|
])),
|
Expanded(child: Container()),
|
_exchanging > 0
|
? Row(
|
crossAxisAlignment:
|
CrossAxisAlignment.center,
|
children: [
|
Text(
|
"折算中:$_exchanging个",
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 12),
|
),
|
const SizedBox(
|
width: 5,
|
),
|
InkWell(
|
onTap: () {
|
DialogUtil.showDialog(
|
context,
|
MyAlertDialog(
|
"温馨提示",
|
"每日00:00后系统自动将所有金币按照\"一定的\"比例折算为现金。",
|
() {
|
popPage(
|
context);
|
},
|
sureName: "好的",
|
));
|
},
|
child: Image.asset(
|
"assets/imgs/mine/icon_balance_question.png",
|
height: 12,
|
)),
|
])
|
: Container(),
|
],
|
)),
|
])),
|
|
//绑定微信
|
|
const SizedBox(
|
height: 12,
|
),
|
Stack(alignment: Alignment.bottomCenter, children: [
|
Container(
|
height: 47,
|
decoration: const BoxDecoration(
|
color: Color(0xFFE6E6E6),
|
borderRadius: BorderRadius.only(
|
topLeft: Radius.circular(13),
|
topRight: Radius.circular(13)),
|
)),
|
Padding(padding:const EdgeInsets.only(bottom:0), child:
|
Row(
|
children: [
|
Expanded(flex: 1, child: getNavItem("金币记录", 0)),
|
Expanded(flex: 1, child: getNavItem("折算记录", 1)),
|
],
|
))
|
]),
|
Expanded(
|
child: Container(
|
color: Colors.white,
|
child: TabBarView(
|
controller: _tabController,
|
physics: const NeverScrollableScrollPhysics(),
|
children: [
|
KeepAliveWrapper(
|
child: GoldCornRecord(
|
exchange: false,
|
)),
|
KeepAliveWrapper(
|
child: GoldCornRecord(
|
exchange: true,
|
)),
|
],
|
),
|
))
|
])))
|
],
|
));
|
}
|
|
Widget getNavItem(title, index) {
|
return InkWell(
|
onTap: () {
|
setState(() {
|
selectedIndex = index;
|
});
|
_tabController!.index = index;
|
},
|
child: Container(
|
height: 50,
|
alignment: Alignment.center,
|
decoration: selectedIndex == index
|
? BoxDecoration(
|
color: Colors.white,
|
borderRadius: const BorderRadius.only(
|
topLeft: Radius.circular(13),
|
topRight: Radius.circular(13)),
|
boxShadow: [
|
BoxShadow(
|
color: const Color(0x80989898),
|
offset: Offset((index == 0 ? 2 : -2), 0))
|
])
|
: null,
|
child: Text(
|
title,
|
style: TextStyle(
|
color: selectedIndex == index
|
? ColorConstant.theme
|
: const Color(0xFF666666),
|
fontSize: 15),
|
),
|
));
|
}
|
}
|
|
class GoldCornRecord extends StatefulWidget {
|
GoldCornRecord({Key? key, required this.exchange}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final bool exchange;
|
|
@override
|
_GoldCornRecordState createState() => _GoldCornRecordState();
|
}
|
|
class _GoldCornRecordState extends State<GoldCornRecord> {
|
final MyRefreshController _refreshController =
|
MyRefreshController(initialRefresh: false);
|
|
int _page = 1;
|
|
List<GoldCoreRecordModel> _recordList = [];
|
|
@override
|
void initState() {
|
super.initState();
|
_refresh();
|
}
|
|
//下拉刷新
|
void _refresh() {
|
if (_refreshController.dataNormal != null) {
|
_refreshController.dataNormal!();
|
}
|
_refreshController.loadComplete();
|
_getRecordList(1);
|
}
|
|
//上拉加载
|
void _loadMore() {
|
_getRecordList(_page + 1);
|
}
|
|
//获取队员列表
|
void _getRecordList(int page) async {
|
setState(() {
|
_page = page;
|
});
|
|
Map<String, dynamic>? result = await (widget.exchange
|
? GoldCornApiUtil.listExchangeRecord(context, _page)
|
: GoldCornApiUtil.listGetRecord(context, _page));
|
|
_refreshController.refreshCompleted();
|
_refreshController.loadComplete();
|
|
if (result == null && _page == 1&&_recordList.isEmpty) {
|
_refreshController.apiError!();
|
}
|
|
if (result == null || result["code"] != 0) {
|
//页码回滚
|
if (_page > 1) {
|
setState(() {
|
_page = _page - 1;
|
});
|
}
|
return;
|
}
|
//解析数据
|
int count = result["data"]["count"];
|
List<dynamic> list = result["data"]["list"];
|
List<GoldCoreRecordModel> tempList = [];
|
list.forEach((element) {
|
if (widget.exchange) {
|
tempList.add(GoldCoreRecordModel(
|
title: "+¥${element["money"]}元",
|
dateTime: element["dateTime"],
|
num: element["num"]));
|
} else {
|
tempList.add(GoldCoreRecordModel.fromJson(element));
|
}
|
});
|
|
if (_page == 1) {
|
setState(() {
|
_recordList = tempList;
|
});
|
} else {
|
setState(() {
|
_recordList.addAll(tempList);
|
});
|
}
|
|
//判断数据
|
|
if (_recordList.isEmpty) {
|
//空数据
|
_refreshController.dataEmpty!();
|
} else {
|
_refreshController.dataNormal!();
|
if (count <= _recordList.length) {
|
//没有数据了
|
_refreshController.loadNoData();
|
}
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return RefreshListView(
|
refreshController: _refreshController,
|
refresh: () {
|
_refresh();
|
},
|
loadMore: () {
|
_loadMore();
|
},
|
loadTextColor: const Color(0xFFFF8316),
|
content: ListView.builder(
|
itemCount: _recordList.length,
|
itemBuilder: (BuildContext context, int index) {
|
return _getItemView(index, () {});
|
},
|
),
|
);
|
}
|
|
Widget _getItemView(int index, GestureTapCallback onTap) {
|
return InkWell(
|
onTap: () {
|
onTap();
|
},
|
child: Padding(
|
padding:
|
const EdgeInsets.only(top: 20, left: 16, right: 16, bottom: 5),
|
child: Row(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Text(
|
_recordList[index].title!,
|
style: const TextStyle(color: Colors.black, fontSize: 14),
|
),
|
Text(
|
_recordList[index].dateTime!,
|
style: const TextStyle(
|
color: Color(0xFF999999), fontSize: 12, height: 1.5),
|
)
|
],
|
),
|
Column(children: [
|
Row(
|
children: [
|
Image.asset(
|
"assets/imgs/icon_goldcorn.png",
|
height: 22,
|
),
|
Text(
|
widget.exchange
|
? " -${_recordList[index].num}"
|
: " +${_recordList[index].num}",
|
style: const TextStyle(
|
color: Color(0xFFFF8316), fontSize: 15),
|
)
|
],
|
),
|
])
|
],
|
)));
|
}
|
}
|