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

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