YSNews.dart 19 KB

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