基础组件库
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.
 
 
 
 
 

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