YSMessage.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter_easyrefresh/easy_refresh.dart';
  5. import 'package:ysairplane/tools/YSNetWorking.dart';
  6. import 'package:ysairplane/tools/YSTools.dart';
  7. import 'YSSquareArticle.dart';
  8. import 'YSSquareVideo.dart';
  9. class YSMessage extends StatefulWidget {
  10. @override
  11. _YSMessageState createState() => _YSMessageState();
  12. }
  13. class _YSMessageState extends State<YSMessage> {
  14. bool _isShow = false;
  15. int _index = 0;
  16. List _types = [];
  17. List _dataArray = [];
  18. int _page = 1;
  19. @override
  20. void initState() {
  21. Future.delayed(Duration(seconds: 0)).then((value){
  22. _getTypeData();
  23. });
  24. super.initState();
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. backgroundColor: Color(0xFFF0F0F1),
  30. appBar: CupertinoNavigationBar(
  31. backgroundColor: Colors.white,
  32. leading: GestureDetector(child: Icon(Icons.arrow_back_ios,size: 15,color: Color(0xFF000000),),onTap: (){Navigator.pop(context);},),
  33. border: Border(),
  34. middle: GestureDetector(
  35. onTap: (){
  36. setState(() {
  37. _isShow = !_isShow;
  38. });
  39. },
  40. child: Row(
  41. mainAxisSize: MainAxisSize.min,
  42. children: [
  43. Text(_types.length>0?'${_types[_index]['name']}':'',style: TextStyle(fontSize: zsp(36),color: Color(0xFF000000)),),
  44. Icon(Icons.keyboard_arrow_down,size: 15,color: Color(0xFF000000),),
  45. ],
  46. ),
  47. ),
  48. ),
  49. body: Stack(
  50. children: [
  51. EasyRefresh(
  52. onRefresh: _refresh,
  53. onLoad: _loadMore,
  54. header: TaurusHeader(
  55. ),
  56. footer: TaurusFooter(
  57. ),
  58. child: ListView.separated(
  59. shrinkWrap: true,
  60. itemBuilder: (context,index){
  61. return Container(
  62. padding: EdgeInsets.all(hsp(30)),
  63. color: Colors.white,
  64. child: _dataArray[index]['type']=='4'?Column(
  65. crossAxisAlignment: CrossAxisAlignment.start,
  66. children: [
  67. Text('系统消息',style: TextStyle(fontSize: zsp(28),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold),),
  68. Container(
  69. child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),),
  70. margin: EdgeInsets.only(top: hsp(10),bottom: hsp(20)),
  71. ),
  72. Container(
  73. child: Text('${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434)),),
  74. width: MediaQuery.of(context).size.width-hsp(170),
  75. )
  76. ],
  77. )
  78. :_dataArray[index]['type']=='2'?Row(
  79. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  80. children: [
  81. Row(
  82. children: [
  83. Container(
  84. height: hsp(66),
  85. width: hsp(66),
  86. decoration: BoxDecoration(
  87. color: Colors.lightBlue,
  88. borderRadius: BorderRadius.all(Radius.circular(hsp(33)))
  89. ),
  90. margin: EdgeInsets.only(right: wsp(20)),
  91. child: ClipRRect(
  92. borderRadius: BorderRadius.all(Radius.circular(hsp(33))),
  93. child: CachedNetworkImage(
  94. imageUrl: '${_dataArray[index]['users']['avatar']}',
  95. fit: BoxFit.fill,
  96. ),
  97. ),
  98. ),
  99. Column(
  100. crossAxisAlignment: CrossAxisAlignment.start,
  101. children: [
  102. RichText(
  103. text: TextSpan(
  104. text: '${_dataArray[index]['users']['nickname']}',
  105. style: TextStyle(fontSize: zsp(22),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold),
  106. children: [
  107. TextSpan(
  108. text: ' ${_dataArray[index]['content']}',
  109. style: TextStyle(color: Color(0xFF575757),fontWeight: FontWeight.normal),
  110. )
  111. ]
  112. ),
  113. ),
  114. Container(
  115. child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),),
  116. margin: EdgeInsets.only(top: hsp(10)),
  117. ),
  118. ],
  119. )
  120. ],
  121. ),
  122. GestureDetector(
  123. child: Container(
  124. height: hsp(60),
  125. decoration: BoxDecoration(
  126. color: Color(0xFF007AFF),
  127. borderRadius: BorderRadius.all(Radius.circular(50))
  128. ),
  129. alignment: Alignment.center,
  130. child: Text(_dataArray[index]['isAttention']==1?'取消关注':'关注',style: TextStyle(color: Colors.white,fontSize: zsp(24)),),
  131. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  132. ),
  133. onTap: (){
  134. _postAuthorAttention(index);
  135. },
  136. )
  137. ],
  138. ):Column(
  139. children: [
  140. Row(
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. children: [
  143. Container(
  144. height: hsp(66),
  145. width: hsp(66),
  146. decoration: BoxDecoration(
  147. color: Colors.lightBlue,
  148. borderRadius: BorderRadius.all(Radius.circular(hsp(33)))
  149. ),
  150. margin: EdgeInsets.only(right: wsp(20)),
  151. child: ClipRRect(
  152. borderRadius: BorderRadius.all(Radius.circular(hsp(33))),
  153. child: CachedNetworkImage(
  154. imageUrl: '${_dataArray[index]['users']['avatar']}',
  155. fit: BoxFit.fill,
  156. ),
  157. ),
  158. ),
  159. Column(
  160. crossAxisAlignment: CrossAxisAlignment.start,
  161. children: [
  162. Text('${_dataArray[index]['users']['nickname']}',
  163. style: TextStyle(fontSize: zsp(28),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold),),
  164. Container(
  165. child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),),
  166. margin: EdgeInsets.only(top: hsp(10)),
  167. ),
  168. ],
  169. )
  170. ],
  171. ),
  172. Container(
  173. child: Text('${_dataArray[index]['type']=='3'?'@我 ':''}${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434)),),
  174. width: MediaQuery.of(context).size.width-hsp(66),
  175. margin: EdgeInsets.only(top: hsp(30),bottom: hsp(20)),
  176. ),
  177. GestureDetector(
  178. onTap: (){
  179. Navigator.of(context,rootNavigator: true).push(
  180. CupertinoPageRoute(
  181. builder: (context){
  182. return _dataArray[index]['squareMessage']['type']==1?YSSquareArticle(squareId: _dataArray[index]
  183. ['squareMessage']['id'],typeId: _dataArray[index]['squareMessage']['type'],)
  184. :YSSquareVideo(squareId: _dataArray[index]['squareMessage']['id'],typeId: _dataArray[index]['squareMessage']['type'],);
  185. }
  186. )
  187. );
  188. },
  189. child: Row(
  190. children: [
  191. Container(
  192. height: hsp(120),
  193. width: hsp(120),
  194. child: CachedNetworkImage(
  195. imageUrl: '${_dataArray[index]['squareMessage']['cover']}',
  196. fit: BoxFit.fill,
  197. ),
  198. ),
  199. Container(
  200. height: hsp(120),
  201. width: MediaQuery.of(context).size.width-hsp(186),
  202. color: Color(0xFFF4F6F8),
  203. child: Text('${_dataArray[index]['squareMessage']['title']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF7F7F7F)),maxLines: 2,overflow: TextOverflow.ellipsis,),
  204. padding: EdgeInsets.all(hsp(20)),
  205. )
  206. ],
  207. ),
  208. )
  209. ],
  210. ),
  211. );
  212. },
  213. separatorBuilder: (context,index){
  214. return Divider(height: hsp(12),thickness: hsp(12),color: Color(0xFFF0F0F1),);
  215. },
  216. itemCount: _dataArray.length,
  217. padding: EdgeInsets.only(top: hsp(12),bottom: hsp(43)),
  218. ),
  219. ),
  220. if(_isShow==true)Column(
  221. children: [
  222. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),),
  223. Container(
  224. color: Colors.white,
  225. child: ListView.separated(
  226. shrinkWrap: true,
  227. itemBuilder: (context,index){
  228. return GestureDetector(
  229. onTap: (){
  230. _index = index;
  231. _isShow = false;
  232. _refresh();
  233. },
  234. child: Container(
  235. height: hsp(105),
  236. color: Colors.white,
  237. alignment: Alignment.centerLeft,
  238. padding: EdgeInsets.only(left: wsp(50),right: wsp(50)),
  239. child: Row(
  240. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  241. children: [
  242. Text('${_types[index]['name']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434),
  243. fontWeight: index==_index?FontWeight.bold:FontWeight.normal),),
  244. Icon(Icons.check,color: index==_index?Color(0xFF007AFF):Colors.transparent,size: hsp(40),)
  245. ],
  246. )
  247. ),
  248. );
  249. },
  250. separatorBuilder: (context,index){
  251. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),);
  252. },
  253. itemCount: _types.length,
  254. physics: NeverScrollableScrollPhysics(),
  255. ),
  256. ),
  257. GestureDetector(
  258. onTap: (){
  259. setState(() {
  260. _isShow = false;
  261. });
  262. },
  263. child: Container(
  264. height: MediaQuery.of(context).size.height-hsp(105)*_types.length-0.5*_types.length-MediaQuery.of(context).padding.top-44,
  265. width: MediaQuery.of(context).size.width,
  266. color: Colors.black54,
  267. ),
  268. )
  269. ],
  270. )
  271. ],
  272. ),
  273. );
  274. }
  275. _getTypeData() async{
  276. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message/type',parameter: {},isLoading: true,refresh: _getTypeData,isToken: true);
  277. if(dict!=null){
  278. _types = dict['data'];
  279. _types.insert(0, {'id': 0, 'name': '全部消息', 'type': 0, 'status': 1});
  280. _refresh();
  281. }
  282. }
  283. Future<void> _refresh() async{
  284. _page = 1;
  285. Map request = {};
  286. request['pageNo'] = _page;
  287. request['pageSize'] = 10;
  288. if(_index!=0){
  289. request['type'] = _types[_index]['type'];
  290. }
  291. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message',parameter: request,
  292. isLoading: true,refresh: _refresh,isToken: true);
  293. if(dict!=null){
  294. setState(() {
  295. _dataArray = dict['data']['resultList'];
  296. });
  297. }
  298. }
  299. Future<void> _loadMore() async{
  300. _page++;
  301. Map request = {};
  302. request['pageNo'] = _page;
  303. request['pageSize'] = 10;
  304. if(_index!=0){
  305. request['type'] = _types[_index]['type'];
  306. }
  307. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message',parameter: request,
  308. isLoading: true,refresh: _loadMore,isToken: true);
  309. if(dict!=null){
  310. setState(() {
  311. _dataArray.addAll(dict['data']['resultList']);
  312. });
  313. }
  314. }
  315. _postAuthorAttention(int index) async{
  316. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention',
  317. parameter: {'userId':_dataArray[index]['users']['id']},isLoading: false,isToken: true,refresh: (){});
  318. if(dict!=null){
  319. setState(() {
  320. _dataArray[index]['isAttention'] = dict['data'];
  321. });
  322. }
  323. }
  324. }