基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

361 lines
13 KiB

  1. import 'dart:convert';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:tab_indicator_styler/tab_indicator_styler.dart';
  5. import 'package:zhiying_base_widget/dialog/loading/loading.dart';
  6. import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
  7. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/model/wallet_detail_model.dart';
  8. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_bloc.dart';
  9. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_sk.dart';
  10. import 'package:cached_network_image/cached_network_image.dart';
  11. import 'package:zhiying_comm/zhiying_comm.dart';
  12. import 'package:provider/provider.dart';
  13. class WalletDetail extends StatefulWidget {
  14. final Map<String, dynamic> data;
  15. const WalletDetail(
  16. this.data, {
  17. Key key,
  18. }) : super(key: key);
  19. @override
  20. _WalletDetailState createState() => _WalletDetailState();
  21. }
  22. class _WalletDetailState extends State<WalletDetail> with TickerProviderStateMixin {
  23. WalletDetailModel _model;
  24. TabController _tabController;
  25. WalletDetailBloc _bloc;
  26. @override
  27. void initState() {
  28. if (widget.data != null) {
  29. _model = WalletDetailModel.fromJson(json.decode(widget.data['data']));
  30. _tabController = TabController(length: _model.providers.length, vsync: this);
  31. }
  32. _bloc = new WalletDetailBloc();
  33. _bloc.loadData(_model.providers[0].type, _bloc.selectDay);
  34. super.initState();
  35. }
  36. @override
  37. void didChangeDependencies() {
  38. RefreshListener.listen(context, (event) {
  39. if (event == "refresh") {
  40. if (_bloc.currentType == null) {
  41. _bloc.loadData(_model.providers[0].type, _bloc.selectDay);
  42. } else {
  43. _bloc.loadData(_bloc.currentType, _bloc.selectDay);
  44. }
  45. }
  46. });
  47. super.didChangeDependencies();
  48. }
  49. @override
  50. void dispose() {
  51. super.dispose();
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return StreamBuilder(
  56. stream: _bloc.outData,
  57. builder: (context, asyn) {
  58. if (_bloc.currentWalletDetailDataModel == null) {
  59. ///骨架图
  60. return WalletDetailSkeleton();
  61. }
  62. Loading.dismiss();
  63. return Container(
  64. decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
  65. margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 7.5, bottom: 7.5),
  66. padding: const EdgeInsets.only(bottom: 13),
  67. child: Column(
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: <Widget>[
  70. Container(
  71. padding: EdgeInsets.only(top: 12),
  72. child: TabBar(
  73. indicatorWeight: 3,
  74. indicator: MaterialIndicator(
  75. height: 2,
  76. bottomLeftRadius: 1,
  77. bottomRightRadius: 1,
  78. horizontalPadding: 0,
  79. topLeftRadius: 1,
  80. topRightRadius: 1,
  81. color: HexColor.fromHex(_model.providers[0].selectColor),
  82. ),
  83. isScrollable: true,
  84. unselectedLabelColor: HexColor.fromHex(_model.providers[0].unselectColor),
  85. labelColor: HexColor.fromHex(_model.providers[0].selectColor),
  86. controller: _tabController,
  87. indicatorColor: HexColor.fromHex(_model.providers[0].selectColor),
  88. indicatorSize: TabBarIndicatorSize.label,
  89. onTap: (index) {
  90. ///变更平台
  91. Loading.show(context);
  92. changeProvider(_model.providers[index].type);
  93. },
  94. tabs: _buildTabs()),
  95. ),
  96. ///日期选择
  97. Container(
  98. height: 50,
  99. alignment: Alignment.center,
  100. child: ListView.builder(
  101. padding: EdgeInsets.only(left: 8),
  102. itemCount: _model.dateList.length,
  103. scrollDirection: Axis.horizontal,
  104. itemBuilder: _buildTimeItem,
  105. ),
  106. ),
  107. /// 数据
  108. Container(
  109. height: 63,
  110. margin: EdgeInsets.only(top: 16, left: 15, right: 15),
  111. width: double.infinity,
  112. decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(_model.providerDashbord.finish.bgImg), fit: BoxFit.fill)),
  113. child: Column(
  114. mainAxisAlignment: MainAxisAlignment.center,
  115. children: <Widget>[
  116. _model.providerDashbord.finish.isShow == "1"
  117. ? Container()
  118. : Padding(
  119. padding: const EdgeInsets.all(8.0),
  120. child: Text(
  121. _model.providerDashbord.finish.text,
  122. style: TextStyle(fontSize: 14, color: HexColor.fromHex(_model.providerDashbord.finish.textColor)),
  123. ),
  124. ),
  125. Row(
  126. mainAxisAlignment: MainAxisAlignment.center,
  127. children: <Widget>[
  128. Text(
  129. _model.providerDashbord.finish.text ?? "",
  130. style: TextStyle(color: Colors.black, fontSize: 11),
  131. ),
  132. InkWell(
  133. child: Padding(
  134. padding: const EdgeInsets.all(8.0),
  135. child: CachedNetworkImage(
  136. imageUrl: _model.providerDashbord.finish.tipIcon ?? "",
  137. width: 10,
  138. height: 10,
  139. fit: BoxFit.fill,
  140. ),
  141. ),
  142. onTap: () {
  143. ///显示弹窗
  144. showTipDialog(null, _model.providerDashbord.finish.tipText);
  145. })
  146. ],
  147. ),
  148. Text(
  149. _bloc.selectDateData.finish ?? "",
  150. style: TextStyle(color: Colors.red, fontSize: 20, fontFamily: 'Din', package: 'zhiying_comm', fontWeight: FontWeight.bold),
  151. )
  152. ],
  153. ),
  154. ),
  155. Container(
  156. child: ListView.builder(
  157. padding: EdgeInsets.all(0),
  158. itemCount: 3,
  159. shrinkWrap: true,
  160. physics: NeverScrollableScrollPhysics(),
  161. itemBuilder: (context, index) {
  162. return _buildBottomItem(context, index, _model.providerDashbord);
  163. }),
  164. )
  165. ],
  166. ),
  167. );
  168. },
  169. );
  170. }
  171. ///平台选择
  172. _buildTabs() {
  173. List<Widget> listWidget = List();
  174. for (var item in _model.providers) {
  175. listWidget.add(Text(
  176. item.name,
  177. style: TextStyle(
  178. fontSize: 14,
  179. ),
  180. ));
  181. }
  182. return listWidget;
  183. }
  184. Widget _buildTimeItem(BuildContext context, int index) {
  185. var item = _model.dateList[index];
  186. return InkWell(
  187. child: Container(
  188. margin: EdgeInsets.only(top: 0, left: 8, right: 8),
  189. decoration: BoxDecoration(
  190. image: DecorationImage(image: CachedNetworkImageProvider(item.type == _bloc.selectDateData.type ? item.btnImg ?? "" : item.btnNoColorImg ?? ""), fit: BoxFit.fitWidth),
  191. ),
  192. child: Padding(
  193. padding: const EdgeInsets.only(left: 16, right: 16),
  194. child: Center(
  195. child: Text(
  196. item.text,
  197. style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.type == _bloc.selectDateData.type ? item.textSelectColor : item.textUnselectColor)),
  198. )),
  199. ),
  200. ),
  201. onTap: () {
  202. Loading.show(context);
  203. _bloc.selectDay = item.type;
  204. _bloc.loadData(_bloc.currentType, _bloc.selectDay);
  205. },
  206. );
  207. }
  208. ///底部显示
  209. Widget _buildBottomItem(BuildContext context, int index, ProviderDashbord dashbord) {
  210. SelfBuy item;
  211. if (index == 0) {
  212. item = dashbord.selfBuy;
  213. } else if (index == 1) {
  214. item = dashbord.directPromote;
  215. } else {
  216. item = dashbord.indirectPromote;
  217. }
  218. var dataMap = _bloc.selectDateData.toJson();
  219. return Container(
  220. child: Column(
  221. children: <Widget>[
  222. SizedBox(
  223. height: 7.5,
  224. ),
  225. item.isShow == "0"
  226. ? Container()
  227. : Text(
  228. item.title,
  229. style: TextStyle(color: HexColor.fromHex(item.titleColor), fontSize: 14),
  230. ),
  231. SizedBox(
  232. height: 7.5,
  233. ),
  234. Row(
  235. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  236. children: <Widget>[
  237. Expanded(
  238. child: Container(
  239. height: 61.5,
  240. margin: EdgeInsets.only(right: 8, left: 15),
  241. padding: EdgeInsets.only(left: 10),
  242. decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[0].bgImg ?? ""), fit: BoxFit.fill)),
  243. child: Column(
  244. mainAxisAlignment: MainAxisAlignment.center,
  245. crossAxisAlignment: CrossAxisAlignment.start,
  246. children: <Widget>[
  247. Row(
  248. children: <Widget>[
  249. Text(
  250. item.itemList[0].text ?? "",
  251. style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[0].textColor)),
  252. ),
  253. InkWell(
  254. child: Padding(
  255. padding: const EdgeInsets.all(8.0),
  256. child: CachedNetworkImage(
  257. imageUrl: item.itemList[0].tipIcon,
  258. width: 10,
  259. height: 10,
  260. fit: BoxFit.fill,
  261. ),
  262. ),
  263. onTap: () {
  264. //弹窗
  265. showTipDialog(null, item.itemList[0].tipText);
  266. },
  267. )
  268. ],
  269. ),
  270. Text(dataMap[item.itemList[0].vauleKey],
  271. style: TextStyle(
  272. fontFamily: 'Din',
  273. package: 'zhiying_comm',
  274. fontWeight: FontWeight.bold,
  275. fontSize: 17,
  276. color: HexColor.fromHex(item.itemList[1].valueColor),
  277. ))
  278. ],
  279. )),
  280. ),
  281. Expanded(
  282. child: Container(
  283. height: 61.5,
  284. margin: EdgeInsets.only(
  285. left: 8,
  286. right: 15,
  287. ),
  288. padding: EdgeInsets.only(left: 10),
  289. decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[1].bgImg ?? ""), fit: BoxFit.fill)),
  290. child: Column(
  291. mainAxisAlignment: MainAxisAlignment.center,
  292. crossAxisAlignment: CrossAxisAlignment.start,
  293. children: <Widget>[
  294. Row(
  295. children: <Widget>[
  296. Text(
  297. item.itemList[1].text ?? "",
  298. style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[1].textColor)),
  299. ),
  300. InkWell(
  301. child: Padding(
  302. padding: const EdgeInsets.all(8.0),
  303. child: CachedNetworkImage(
  304. imageUrl: item.itemList[1].tipIcon,
  305. width: 10,
  306. height: 10,
  307. fit: BoxFit.fill,
  308. ),
  309. ),
  310. onTap: () {
  311. //弹窗
  312. showTipDialog(null, item.itemList[1].tipText);
  313. },
  314. )
  315. ],
  316. ),
  317. Text(
  318. dataMap[item.itemList[1].vauleKey],
  319. style: TextStyle(fontSize: 17, color: HexColor.fromHex(item.itemList[1].valueColor), fontFamily: 'Din', package: 'zhiying_comm', fontWeight: FontWeight.bold),
  320. )
  321. ],
  322. ),
  323. ))
  324. ],
  325. )
  326. ],
  327. ),
  328. );
  329. }
  330. ///变更平台
  331. void changeProvider(String type) {
  332. _bloc.currentType = type;
  333. _bloc.loadData(type, _bloc.selectDay);
  334. }
  335. ///显示提示框
  336. void showTipDialog(String title, String content) {
  337. showDialog(context: context, child: TipDialog(content: content));
  338. }
  339. }