YSNews.dart 19 KB

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