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

wallet_data.dart 7.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import 'dart:convert';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/model/wallet_header_model.dart';
  6. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_bloc.dart';
  7. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'package:provider/provider.dart';
  10. class WalletData extends StatefulWidget {
  11. final Map<String, dynamic> data;
  12. WalletData(this.data, {Key key}) : super(key: key);
  13. @override
  14. _WalletDataState createState() => _WalletDataState();
  15. }
  16. class _WalletDataState extends State<WalletData> {
  17. Map<String, dynamic> data;
  18. WalletDataBloc _bloc;
  19. Map<String, dynamic> dataModel;
  20. @override
  21. void initState() {
  22. super.initState();
  23. data = widget.data;
  24. _bloc = WalletDataBloc();
  25. _bloc.loadHeaderData();
  26. }
  27. @override
  28. void didChangeDependencies() {
  29. RefreshListener.listen(context, (event) {
  30. _bloc.loadHeaderData();
  31. });
  32. super.didChangeDependencies();
  33. }
  34. @override
  35. void dispose() {
  36. super.dispose();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. WalletHeaderModel model;
  41. return StreamBuilder(
  42. stream: _bloc.outData,
  43. builder: (context, asn) {
  44. dataModel = asn.data;
  45. if (data.containsKey('data')) {
  46. Map<String, dynamic> temp = json.decode(data['data']);
  47. model = WalletHeaderModel.fromJson(temp);
  48. } else {
  49. return WalletDataSkeleton();
  50. }
  51. return Container(
  52. width: double.infinity,
  53. child: dataModel == null
  54. ? WalletDataSkeleton()
  55. : Container(
  56. margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 10),
  57. padding: EdgeInsets.only(left: 18, right: 13),
  58. decoration: BoxDecoration(
  59. image: DecorationImage(
  60. image: CachedNetworkImageProvider(
  61. model?.headerImg ?? ""),
  62. fit: BoxFit.fill)),
  63. height: 145,
  64. child: Column(
  65. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  66. children: <Widget>[
  67. Row(
  68. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  69. children: <Widget>[
  70. Row(
  71. children: <Widget>[
  72. CachedNetworkImage(
  73. imageUrl: model?.headerAvatar ?? "",
  74. height: 33,
  75. width: 26,
  76. fit: BoxFit.fill,
  77. ),
  78. Padding(
  79. padding: const EdgeInsets.all(8.0),
  80. child: Column(
  81. crossAxisAlignment:
  82. CrossAxisAlignment.start,
  83. children: <Widget>[
  84. Text(
  85. model?.headerCashOutText ?? "",
  86. style: TextStyle(
  87. fontSize: 12.5,
  88. color: HexColor.fromHex(
  89. model?.headerCashOutTextColor ??
  90. "")),
  91. ),
  92. Text(
  93. dataModel.containsKey(
  94. model.headerCashOutKey)
  95. ? dataModel[model.headerCashOutKey]
  96. : "",
  97. style: TextStyle(
  98. fontSize: 20,
  99. color: HexColor.fromHex(
  100. model.headerCashOutTextColor),
  101. fontFamily: 'Din-Bold',
  102. package: 'zhiying_comm',
  103. ),
  104. ),
  105. ],
  106. ),
  107. )
  108. ],
  109. ),
  110. GestureDetector(
  111. onTap: () {
  112. RouterUtil.route(
  113. model, model.toJson(), context);
  114. },
  115. child: Container(
  116. decoration: BoxDecoration(
  117. borderRadius: BorderRadius.circular(10),
  118. image: DecorationImage(
  119. image: CachedNetworkImageProvider(
  120. model.headerCashOutBtnImg ?? ''),
  121. fit: BoxFit.fill),
  122. ),
  123. child: Padding(
  124. padding: EdgeInsets.only(
  125. left: 14.5,
  126. right: 14.5,
  127. top: 10,
  128. bottom: 10),
  129. child: Text(
  130. model.headerCashOutBtnText,
  131. style: TextStyle(
  132. color: HexColor.fromHex(
  133. model.headerCashOutBtnTextColor)),
  134. ),
  135. ),
  136. ),
  137. )
  138. ],
  139. ),
  140. Divider(
  141. height: 1,
  142. ),
  143. Row(
  144. mainAxisAlignment: MainAxisAlignment.spaceAround,
  145. children: _buildTopListItem(model))
  146. ],
  147. ),
  148. ));
  149. },
  150. );
  151. }
  152. ///构建顶部Item
  153. _buildTopListItem(WalletHeaderModel model) {
  154. List<Widget> listWidget = List();
  155. for (var item in model.headerBottomList) {
  156. listWidget.add(Column(
  157. mainAxisSize: MainAxisSize.min,
  158. children: <Widget>[
  159. Text(
  160. dataModel.containsKey(item.valueKey)
  161. ? dataModel[item.valueKey]
  162. : "",
  163. style: TextStyle(
  164. color: HexColor.fromHex(item.valueColor),
  165. fontSize: 15,
  166. fontFamily: 'Din-Bold',
  167. package: 'zhiying_comm'),
  168. ),
  169. Text(
  170. item.text,
  171. style: TextStyle(
  172. color: HexColor.fromHex(item.textColor), fontSize: 11),
  173. ),
  174. ],
  175. ));
  176. }
  177. return listWidget;
  178. }
  179. }