vip_center.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:twong/api/index.dart';
  4. import 'package:twong/config/style.dart';
  5. import 'package:twong/models/index.dart';
  6. import 'package:twong/router/base.dart';
  7. import 'package:twong/utils/index.dart';
  8. import 'package:twong/widgets/app_bar.dart';
  9. class VipCenterPage extends StatefulWidget {
  10. @override
  11. State<StatefulWidget> createState() {
  12. return _VipCenterState();
  13. }
  14. }
  15. class _VipCenterState extends State<VipCenterPage> {
  16. VipInfo _info;
  17. List<VipConfig> configs;
  18. @override
  19. void initState() {
  20. super.initState();
  21. loadData();
  22. }
  23. loadData() async {
  24. Network.inst.getVipConfig().then((value) {
  25. configs = value;
  26. Network.inst.getVipInfo().then((info) {
  27. setState(() {
  28. _info = info;
  29. });
  30. });
  31. });
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. appBar: DAppBar("会员中心"),
  37. backgroundColor: DColors.back,
  38. body: SafeArea(
  39. child: _info == null ? Center(child: Utils.loadingWidget) : Container(
  40. margin: EdgeInsets.only(left: 12.px, right: 12.px),
  41. child: ListView(
  42. physics: ClampingScrollPhysics(),
  43. children: [
  44. _buildVipCard(),
  45. _buildVipPromotion(),
  46. _buildVipInfo(),
  47. ],
  48. ),
  49. ),
  50. ),
  51. );
  52. }
  53. Widget _buildVipCard() {
  54. return Container(
  55. height: 180.px,
  56. margin: EdgeInsets.only(top: 6.px, bottom: 12.px),
  57. decoration: BoxDecoration(
  58. borderRadius: BorderRadius.circular(6.px),
  59. image: DecorationImage(
  60. fit: BoxFit.fitHeight,
  61. image: CachedNetworkImageProvider(configs[Cache.user.vip_level - 1].image)
  62. )
  63. ),
  64. child: Column(
  65. crossAxisAlignment: CrossAxisAlignment.start,
  66. children: [
  67. Container(
  68. margin: EdgeInsets.only(left: 12.px, top: 6.px),
  69. child: Text(Cache.user.vip_card_id, style: TextStyle(fontSize: 16.px,
  70. fontWeight: FontWeight.bold, color: Colors.black)),
  71. ),
  72. Spacer(),
  73. Container(
  74. margin: EdgeInsets.only(left: 12.px, bottom: 6.px),
  75. child: Text(Utils.formatData(Cache.user.vip_time)),
  76. )
  77. ],
  78. ),
  79. );
  80. }
  81. Widget _buildVipPromotion() {
  82. return Container(
  83. padding: EdgeInsets.all(6.px),
  84. decoration: BoxDecoration(
  85. color: Colors.white,
  86. borderRadius: BorderRadius.circular(6.px),
  87. ),
  88. margin: EdgeInsets.only(bottom: 12.px),
  89. child: Column(
  90. crossAxisAlignment: CrossAxisAlignment.start,
  91. children: [
  92. Container(
  93. child: Text("会员推广佣金", style: TextStyle(
  94. fontSize: 14.px, fontWeight: FontWeight.bold)),
  95. ),
  96. Divider(),
  97. Column(
  98. children: [
  99. Container(
  100. child: Row(
  101. children: [
  102. Container(
  103. width: 120.px,
  104. child: Text("当前可领取"),
  105. ),
  106. Expanded(child: Text(Utils.formatRMB(_info.money_available,
  107. show: true), style: TextStyle(color: DColors.price))),
  108. FlatButton(
  109. disabledColor: Colors.grey,
  110. onPressed: _info.money_available > 0 ? () {
  111. } : null,
  112. child: Text("领取", style: TextStyle(color: Colors.white)),
  113. shape: StadiumBorder(),
  114. color: DColors.Main,
  115. )
  116. ],
  117. ),
  118. ),
  119. Container(
  120. child: Row(
  121. children: [
  122. Container(
  123. width: 120.px,
  124. child: Text("黄色卡可领取"),
  125. ),
  126. Expanded(child: Text(Utils.formatRMB(_info.money_next,
  127. show: true), style: TextStyle(color: DColors.price))),
  128. FlatButton(
  129. onPressed: () {},
  130. child: Text("去购买", style: TextStyle(color: Colors.white)),
  131. shape: StadiumBorder(),
  132. color: DColors.Main,
  133. )
  134. ],
  135. ),
  136. ),
  137. Container(
  138. child: Row(
  139. children: [
  140. Container(
  141. width: 120.px,
  142. child: Text("当前佣金"),
  143. ),
  144. Expanded(
  145. child: Text(Utils.formatRMB(Cache.user.brokerage_price,
  146. show: true),
  147. style: TextStyle(color: DColors.price))),
  148. FlatButton(
  149. onPressed: () {
  150. Navigator.pushNamed(context, RouteNames.promotion);
  151. },
  152. child: Text("查看", style: TextStyle(color: Colors.white)),
  153. shape: StadiumBorder(),
  154. color: DColors.Main,
  155. )
  156. ],
  157. ),
  158. ),
  159. ],
  160. )
  161. ],
  162. ),
  163. );
  164. }
  165. Widget _buildVipInfo() {
  166. return Container(
  167. decoration: BoxDecoration(
  168. color: Colors.white,
  169. borderRadius: BorderRadius.circular(6.px),
  170. ),
  171. padding: EdgeInsets.all(6.px),
  172. child: Column(
  173. crossAxisAlignment: CrossAxisAlignment.start,
  174. children: [
  175. Container(
  176. child: Text("会员权益说明", style: TextStyle(
  177. fontSize: 14.px, fontWeight: FontWeight.bold)),
  178. ),
  179. Divider(),
  180. Text(_info.card_benefit, style: TextStyle(
  181. height: 2.px, fontSize: 12.px)),
  182. ],
  183. ),
  184. );
  185. }
  186. }