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

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