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

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