coupon_page.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import 'package:bbyyy/my_tools/event_bus.dart';
  2. import 'package:bbyyy/my_tools/my_colors.dart';
  3. import 'package:bbyyy/my_tools/my_views.dart';
  4. import 'package:bbyyy/paegs/mine_page/coupon_page/coupon_view.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:pull_to_refresh/pull_to_refresh.dart';
  7. import '../../../https/MyDio.dart';
  8. import '../../../my_tools/dims.dart';
  9. import '../../../my_tools/my_cookie.dart';
  10. import '../../../my_tools/my_tools.dart';
  11. class CouponPage extends StatefulWidget {
  12. @override
  13. _CouponPageState createState() => _CouponPageState();
  14. }
  15. class _CouponPageState extends State<CouponPage> {
  16. // int selectedIndex = 0;
  17. int page = 1;
  18. RefreshController controller = RefreshController(initialRefresh: true);
  19. @override
  20. void initState() {
  21. // TODO: implement initState
  22. super.initState();
  23. EventBus().on('showCouponIndex', (arg) {
  24. setState(() {
  25. });
  26. });
  27. }
  28. @override
  29. void dispose() {
  30. // TODO: implement dispose
  31. super.dispose();
  32. CouponView().showIndexs.clear();
  33. EventBus().off('showCouponIndex');
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return Scaffold(
  38. backgroundColor: MyColors.cF7F7F7,
  39. body: Column(
  40. children: [
  41. MyViews().myAppBar('优惠券', context, []),
  42. // Container(
  43. // height: 40,
  44. // color: Colors.white,
  45. // child: Row(
  46. // children: [
  47. // GestureDetector(
  48. // onTap: () {
  49. // setState(() {
  50. // selectedIndex = 0;
  51. // });
  52. // },
  53. // behavior: HitTestBehavior.translucent,
  54. // child: Padding(
  55. // padding: EdgeInsets.only(left: 10, right: 10),
  56. // child: Column(
  57. // children: [
  58. // Text(
  59. // '有效',
  60. // style: TextStyle(
  61. // color: selectedIndex == 0
  62. // ? MyColors.cFF4233
  63. // : MyColors.c666666,
  64. // fontSize: 15),
  65. // ),
  66. // Container(
  67. // height: 10,
  68. // child: Visibility(
  69. // child: SvgPicture.asset('images/svg/tab.svg'),
  70. // visible: selectedIndex == 0,
  71. // ),
  72. // )
  73. // ],
  74. // mainAxisAlignment: MainAxisAlignment.end,
  75. // ),
  76. // ),
  77. // ),
  78. // GestureDetector(
  79. // onTap: () {
  80. // setState(() {
  81. // selectedIndex = 1;
  82. // });
  83. // },
  84. // behavior: HitTestBehavior.translucent,
  85. // child: Padding(
  86. // padding: EdgeInsets.only(left: 10, right: 10),
  87. // child: Column(
  88. // children: [
  89. // Text(
  90. // '已用',
  91. // style: TextStyle(
  92. // color: selectedIndex == 1
  93. // ? MyColors.cFF4233
  94. // : MyColors.c666666,
  95. // fontSize: 15),
  96. // ),
  97. // Container(
  98. // height: 10,
  99. // child: Visibility(
  100. // child: SvgPicture.asset('images/svg/tab.svg'),
  101. // visible: selectedIndex == 1,
  102. // ),
  103. // )
  104. // ],
  105. // mainAxisAlignment: MainAxisAlignment.end,
  106. // ),
  107. // ),
  108. // )
  109. // ],
  110. // mainAxisAlignment: MainAxisAlignment.spaceAround,
  111. // ),
  112. // ),
  113. Expanded(
  114. child: SmartRefresher(
  115. controller: controller,
  116. onRefresh: onRefresh,
  117. onLoading: onLoading,
  118. enablePullUp: true,
  119. enablePullDown: true,
  120. child: ListView.builder(
  121. itemBuilder: (c, index) {
  122. return CouponView().ticketItem(index);
  123. },
  124. itemCount: 20,
  125. padding:
  126. EdgeInsets.only(top: 5, left: 24, right: 24, bottom: 20),
  127. ),
  128. ),
  129. ),
  130. ],
  131. ),
  132. );
  133. }
  134. void onRefresh() {
  135. page = 1;
  136. checkCoupons();
  137. }
  138. void onLoading() {
  139. page++;
  140. checkCoupons();
  141. }
  142. checkCoupons() {
  143. MyDio().query({
  144. "key": "coupon",
  145. "filters": [
  146. {
  147. "conditions": ["user_uid==${MyCookie().getUID()}"]
  148. }
  149. ],
  150. "dims": couponDims,
  151. "paging": [page, 20]
  152. }, (response, hasError) {
  153. endRe(controller);
  154. }, (error) {
  155. endRe(controller);
  156. });
  157. }
  158. }