YSMessage.dart 14 KB

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