TipList.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import '../styles/colors.dart';
  4. import 'dart:ui';
  5. import '../styles/totast.dart';
  6. import 'package:flutter_redux/flutter_redux.dart';
  7. import '../redux/AppState.dart';
  8. import '../model/SystemNotice.dart';
  9. import '../net/HttpManager.dart';
  10. import '../net/Result.dart';
  11. import 'TipInfo.dart';
  12. class TipList extends StatefulWidget {
  13. @override
  14. TipListState createState() => TipListState();
  15. }
  16. class TipListState extends State<TipList> {
  17. int currentPage = 1;
  18. List<SystemNotice> tipList = [];
  19. bool isMore = false;
  20. ScrollController _mControll;
  21. void getListPage() async {
  22. isMore = false;
  23. Toast.show(context, '加载中', -1, 'loading');
  24. Result res = await HttpManager.get("systemNotice/page", data: {
  25. "userId": StoreProvider.of<AppState>(context).state.userInfo.id,
  26. "currentPage": currentPage,
  27. "pageNumber": 20
  28. });
  29. Toast.hide();
  30. List<SystemNotice> list = tipList;
  31. if (currentPage == 1) {
  32. list = [];
  33. }
  34. if (res.success) {
  35. for (var item in res.data['pp']) {
  36. SystemNotice tip = SystemNotice.fromJson(item);
  37. list.add(tip);
  38. }
  39. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  40. isMore = true;
  41. }
  42. } else {}
  43. setState(() {
  44. tipList = list;
  45. });
  46. }
  47. @override
  48. void initState() {
  49. super.initState();
  50. _mControll = new ScrollController();
  51. Future.delayed(Duration(milliseconds: 100), () => getListPage());
  52. _mControll.addListener(() {
  53. if (_mControll.position.pixels == _mControll.position.maxScrollExtent) {
  54. if (isMore) {
  55. currentPage++;
  56. getListPage();
  57. }
  58. }
  59. });
  60. }
  61. @override
  62. void dispose() {
  63. super.dispose();
  64. _mControll.dispose();
  65. }
  66. @override
  67. Widget build(BuildContext context) {
  68. return new WillPopScope(
  69. child: Scaffold(
  70. appBar: AppBar(
  71. backgroundColor: PRIMARY_COLOR,
  72. title: Text('通知列表'),
  73. centerTitle: true,
  74. elevation: 0,
  75. ),
  76. body: RefreshIndicator(
  77. color: PRIMARY_COLOR,
  78. backgroundColor: BG_COLOR,
  79. onRefresh: () async {
  80. await new Future.delayed(const Duration(seconds: 1));
  81. int currentPage = 1;
  82. getListPage();
  83. },
  84. child: Container(
  85. color: BG_COLOR,
  86. child: ListView.builder(
  87. physics: AlwaysScrollableScrollPhysics(),
  88. controller: _mControll,
  89. itemCount: tipList.length != 0 ? tipList.length : 1,
  90. itemBuilder: (BuildContext context, int index) {
  91. if (tipList.length == 0) {
  92. return Text(
  93. '数据正在火速加载中...',
  94. style: TextStyle(
  95. color: Colors.white30, fontSize: 13, height: 2),
  96. textAlign: TextAlign.center,
  97. );
  98. }
  99. return TipItem(
  100. tipInfo: tipList[index],
  101. tapInfo: () async {
  102. bool res = await Navigator.push(
  103. context,
  104. new CupertinoPageRoute(
  105. builder: (context) =>
  106. new TipInfo(tipId: tipList[index].id)));
  107. if (res != null) {
  108. setState(() {
  109. tipList = [];
  110. });
  111. currentPage = 1;
  112. getListPage();
  113. }
  114. });
  115. }),
  116. ),
  117. )),
  118. onWillPop: () {
  119. Toast.hide();
  120. print("返回键点击了");
  121. Navigator.pop(context);
  122. return Future.value(false);
  123. });
  124. }
  125. }
  126. typedef OnTapHomeMenu();
  127. class TipItem extends StatelessWidget {
  128. TipItem({Key key, this.tipInfo, this.tapInfo}) : super(key: key);
  129. final SystemNotice tipInfo; // 用来储存传递过来的值
  130. final OnTapHomeMenu tapInfo;
  131. @override
  132. Widget build(BuildContext context) {
  133. return Container(
  134. // height: 108,
  135. margin: EdgeInsets.only(top: 10),
  136. decoration: BoxDecoration(
  137. gradient: LinearGradient(
  138. colors: [Color(0xFF464B6A), Color(0xFF35395E)],
  139. begin: Alignment.topCenter,
  140. end: Alignment.bottomCenter,
  141. ),
  142. ),
  143. child: Material(
  144. color: Colors.transparent,
  145. child: InkWell(
  146. child: Padding(
  147. padding: EdgeInsets.symmetric(horizontal: 15),
  148. child: Column(
  149. children: <Widget>[
  150. Padding(
  151. padding: EdgeInsets.symmetric(vertical: 12),
  152. child: Row(
  153. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  154. children: <Widget>[
  155. Text(
  156. readTimestamp(
  157. tipInfo.createTime, 'yyyy.MM.dd HH:mm:ss'),
  158. style: TextStyle(
  159. color: Color(0xFF9BA0AE), fontSize: 13)),
  160. tipInfo.statusFlag == 0
  161. ? Text('未读',
  162. style: TextStyle(
  163. color: Color(0xFFC2524D),
  164. fontSize: 13,
  165. fontWeight: FontWeight.w600))
  166. : Text('已读',
  167. style: TextStyle(
  168. color: Color(0xFF000000),
  169. fontSize: 13,
  170. fontWeight: FontWeight.w600))
  171. ],
  172. ),
  173. ),
  174. Container(
  175. height: 1,
  176. color: Colors.black26,
  177. ),
  178. Padding(
  179. padding: EdgeInsets.only(top: 10, bottom: 15),
  180. child: Text(tipInfo.content,
  181. style: TextStyle(color: Colors.white, fontSize: 14)),
  182. )
  183. ],
  184. ),
  185. ),
  186. onTap: tapInfo,
  187. ),
  188. ),
  189. );
  190. }
  191. }