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

179 lines
7.0 KiB

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