YSNews.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:flutter_swiper/flutter_swiper.dart';
  5. import 'package:ysairplane2/code/YSNewDetail.dart';
  6. import 'package:ysairplane2/tools/YSNetWorking.dart';
  7. import 'package:ysairplane2/tools/YSTools.dart';
  8. const APPBAR_SCROLL_OFFSET = 100;
  9. class YSNews extends StatefulWidget {
  10. @override
  11. _YSNewsState createState() => _YSNewsState();
  12. }
  13. class _YSNewsState extends State<YSNews> {
  14. ScrollController _scroll = ScrollController();
  15. SwiperController _swiperController = SwiperController();
  16. double appBarAlpha = 0;
  17. double start = 0;
  18. double number = 0;
  19. List _titles = [];
  20. List _lists = [];
  21. List _heads = [];
  22. int _selected = 0;
  23. int _page = 1;
  24. _onScroll(offset) {
  25. double alpha = offset / APPBAR_SCROLL_OFFSET;
  26. if (alpha < 0) {
  27. alpha = 0;
  28. } else if (alpha > 1) {
  29. alpha = 1;
  30. }
  31. setState(() {
  32. appBarAlpha = alpha;
  33. });
  34. }
  35. @override
  36. void initState() {
  37. Future.delayed(Duration(seconds: 0)).then((value){
  38. _getTitleArrayData();
  39. _getHeadArrayData();
  40. });
  41. super.initState();
  42. }
  43. @override
  44. void dispose() {
  45. _swiperController.dispose();
  46. _scroll.dispose();
  47. super.dispose();
  48. }
  49. @override
  50. Widget build(BuildContext context) {
  51. return Scaffold(
  52. body: SingleChildScrollView(
  53. child:Stack(
  54. children: [
  55. Container(
  56. height: MediaQuery.of(context).size.height,
  57. child: Listener(
  58. onPointerDown: (PointerDownEvent pointerDownEvent) {
  59. start = pointerDownEvent.position.dy;
  60. },
  61. onPointerMove: (PointerMoveEvent pointerMoveEvent) {
  62. setState(() {
  63. number = (pointerMoveEvent.position.dy-start)/5;
  64. });
  65. },
  66. onPointerUp: (PointerUpEvent upEvent) {
  67. setState(() {
  68. number = 0;
  69. });
  70. },
  71. child: NotificationListener(
  72. onNotification: (scrollNotification) {
  73. if (scrollNotification is ScrollUpdateNotification &&
  74. scrollNotification.depth == 0) {
  75. //滚动且是列表滚动的时候
  76. _onScroll(scrollNotification.metrics.pixels);
  77. return true;
  78. }else{
  79. return false;
  80. }
  81. },
  82. child: EasyRefresh(
  83. onRefresh: _refreshData,
  84. onLoad: _loadMore,
  85. header: MaterialHeader(
  86. ),
  87. footer: BezierBounceFooter(
  88. backgroundColor: Colors.transparent,
  89. color: Colors.transparent,
  90. ),
  91. child: SingleChildScrollView(
  92. controller: _scroll,
  93. padding: EdgeInsets.all(0),
  94. child: Column(
  95. children: [
  96. if(_heads.length>0)Container(
  97. height: hsp(360)+number,
  98. child: Swiper(
  99. itemBuilder: (BuildContext context, int index) {
  100. return Container(
  101. child: ysImageLoad(
  102. imageUrl: '${_heads[index]['cover']}',
  103. fit: BoxFit.fill,
  104. height: hsp(360)+number,
  105. width: MediaQuery.of(context).size.width
  106. )
  107. );
  108. },
  109. itemCount: _heads.length,
  110. scrollDirection: Axis.horizontal,
  111. loop: true,
  112. duration: 300,
  113. autoplay: true,
  114. onTap: (index) {
  115. Navigator.of(context).push(
  116. CupertinoPageRoute(
  117. builder: (context){
  118. return YSNewDetail(newId: _heads[index]['id'],);
  119. }
  120. )
  121. );
  122. },
  123. pagination: SwiperPagination(
  124. alignment: Alignment.bottomCenter,
  125. builder: DotSwiperPaginationBuilder(
  126. color: Colors.white,
  127. activeColor: Colors.white,
  128. size: 5.0,
  129. activeSize: 10.0
  130. ),
  131. ),
  132. autoplayDisableOnInteraction : true,
  133. controller: _swiperController,
  134. ),
  135. ),
  136. Container(
  137. height: 50,
  138. color: Colors.white,
  139. padding: EdgeInsets.only(left: 15,right: 15,top: 20),
  140. child: ListView.separated(
  141. scrollDirection: Axis.horizontal,
  142. itemBuilder: (context,index){
  143. return GestureDetector(
  144. onTap: (){
  145. setState(() {
  146. _selected = index;
  147. });
  148. _refreshData();
  149. },
  150. child: Container(
  151. height: 30,
  152. child: Column(
  153. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  154. children: [
  155. Text('${_titles[index]['typeName']}',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF007AFF):Color(0xFFCCCCCC),decoration: TextDecoration.none,
  156. fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),),
  157. Container(height: 2,width: 20,color: index==_selected?Color(0xFF007AFF):Colors.transparent,)
  158. ],
  159. ),
  160. ),
  161. );
  162. },
  163. separatorBuilder: (context,index){
  164. return Container(width: 20,);
  165. },
  166. itemCount: _titles.length
  167. ),
  168. ),
  169. Container(
  170. child: ListView.separated(
  171. shrinkWrap: true,
  172. itemBuilder: (context,index){
  173. return GestureDetector(
  174. onTap: (){
  175. Navigator.of(context).push(
  176. CupertinoPageRoute(
  177. builder: (context){
  178. return YSNewDetail(newId: _lists[index]['id'],);
  179. }
  180. )
  181. );
  182. },
  183. child: Container(
  184. color: Colors.white,
  185. padding: EdgeInsets.all(wsp(30)),
  186. child: _lists[index]['coverCount']==1?Row(
  187. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  188. crossAxisAlignment: CrossAxisAlignment.start,
  189. children: [
  190. Column(
  191. children: [
  192. Container(
  193. width: MediaQuery.of(context).size.width-wsp(350),
  194. margin: EdgeInsets.only(bottom: hsp(40)),
  195. child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36))),
  196. ),
  197. Row(
  198. children: [
  199. Container(
  200. height: hsp(45),
  201. padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
  202. child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
  203. color: Color(0xFFC5E6FE),
  204. alignment: Alignment.center,
  205. margin: EdgeInsets.only(right: wsp(15)),
  206. ),
  207. Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
  208. ],
  209. )
  210. ],
  211. crossAxisAlignment: CrossAxisAlignment.start,
  212. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  213. ),
  214. Container(
  215. height: hsp(200),
  216. width: wsp(220),
  217. child: ysImageLoad(
  218. imageUrl: '${_lists[index]['cover']}',
  219. fit: BoxFit.fill,
  220. height: hsp(200),
  221. width: wsp(220),
  222. ),
  223. )
  224. ],
  225. ):_lists[index]['coverCount']==0?Column(
  226. children: [
  227. Container(
  228. width: MediaQuery.of(context).size.width-wsp(60),
  229. margin: EdgeInsets.only(bottom: hsp(40)),
  230. child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36)),maxLines: 2,),
  231. ),
  232. Row(
  233. children: [
  234. Container(
  235. height: hsp(45),
  236. padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
  237. child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
  238. color: Color(0xFFC5E6FE),
  239. alignment: Alignment.center,
  240. margin: EdgeInsets.only(right: wsp(15)),
  241. ),
  242. Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
  243. ],
  244. )
  245. ],
  246. crossAxisAlignment: CrossAxisAlignment.start,
  247. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  248. ):Column(
  249. crossAxisAlignment: CrossAxisAlignment.start,
  250. children: [
  251. Container(
  252. width: MediaQuery.of(context).size.width-wsp(60),
  253. child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36)),maxLines: 2,),
  254. ),
  255. Container(
  256. height: hsp(200),
  257. margin: EdgeInsets.only(top: hsp(30),bottom: hsp(30)),
  258. child: ListView.separated(
  259. itemBuilder: (context,indexSub){
  260. return Container(
  261. height: 200,
  262. width: (MediaQuery.of(context).size.width-wsp(100))/3,
  263. child: ysImageLoad(
  264. imageUrl: '${((_lists[index]['cover'].toString()).split(','))[indexSub]}',
  265. fit: BoxFit.fill,
  266. height: 200,
  267. width: (MediaQuery.of(context).size.width-wsp(100))/3,
  268. ),
  269. );
  270. },
  271. separatorBuilder: (context,indexSub){
  272. return Container(
  273. width: wsp(20),
  274. color: Colors.white,
  275. );
  276. },
  277. itemCount: (_lists[index]['cover'].toString()).split(',').length,
  278. padding: EdgeInsets.all(0),
  279. physics: NeverScrollableScrollPhysics(),
  280. scrollDirection: Axis.horizontal,
  281. ),
  282. width: MediaQuery.of(context).size.width-wsp(60),
  283. ),
  284. Row(
  285. children: [
  286. Container(
  287. height: hsp(45),
  288. padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
  289. child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
  290. color: Color(0xFFC5E6FE),
  291. alignment: Alignment.center,
  292. margin: EdgeInsets.only(right: wsp(15)),
  293. ),
  294. Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
  295. ],
  296. )
  297. ],
  298. ),
  299. ),
  300. );
  301. },
  302. separatorBuilder: (context,index){
  303. return Divider(indent: wsp(32),endIndent: wsp(32),height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),);
  304. },
  305. itemCount: _lists.length,
  306. physics: NeverScrollableScrollPhysics(),
  307. padding: EdgeInsets.only(top: 0.5),
  308. ),
  309. decoration: BoxDecoration(
  310. border: Border(top: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
  311. ),
  312. )
  313. ],
  314. ),
  315. ),
  316. ),
  317. ),
  318. ),
  319. ),
  320. Container(
  321. height: MediaQuery.of(context).padding.top+44,
  322. padding: EdgeInsets.only(left: 15,right: 15,top: MediaQuery.of(context).padding.top),
  323. color: Colors.white.withOpacity(appBarAlpha),
  324. child: Row(
  325. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  326. children: [
  327. GestureDetector(
  328. onTap: (){
  329. Navigator.pop(context);
  330. },
  331. child: Container(
  332. alignment: Alignment.centerLeft,
  333. child: Icon(Icons.arrow_back_ios,size: 20,color: appBarAlpha>0.5?Color(0xFF000000):Colors.white,),
  334. width: (MediaQuery.of(context).size.width-30)/3,
  335. )
  336. ),
  337. if(appBarAlpha>0.5)Container(
  338. child: Text('通航头条',style: TextStyle(fontSize: 18,color: Color(0xFF000000),decoration: TextDecoration.none),),
  339. width: (MediaQuery.of(context).size.width-30)/3,
  340. ),
  341. Container(
  342. width: (MediaQuery.of(context).size.width-30)/3,
  343. )
  344. ],
  345. ),
  346. )
  347. ],
  348. ),
  349. ),
  350. );
  351. }
  352. _getHeadArrayData() async{
  353. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/Carousel/list',parameter: {});
  354. setState(() {
  355. _heads = dict['data'];
  356. });
  357. }
  358. _getTitleArrayData() async{
  359. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/type/list',parameter: {});
  360. if(dict!=null){
  361. setState(() {
  362. _titles = dict['data']['list'];
  363. });
  364. _refreshData();
  365. }
  366. }
  367. Future<void> _refreshData() async{
  368. _page = 1;
  369. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/list',parameter: {'pageNo':_page,'pageSize':10,'headlineTypeId':_titles[_selected]['id']});
  370. if(dict!=null){
  371. setState(() {
  372. _lists = dict['data']['resultList'];
  373. });
  374. }
  375. }
  376. Future<void> _loadMore() async{
  377. _page++;
  378. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/list',parameter: {'pageNo':_page,'pageSize':10,'headlineTypeId':_titles[_selected]['id']});
  379. if(dict!=null){
  380. setState(() {
  381. _lists.addAll(dict['data']['resultList']);
  382. });
  383. }
  384. }
  385. }