TipList.dart 5.7 KB

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