123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyrefresh/easy_refresh.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import 'package:ysairplane/code/YSNewDetail.dart';
- import 'package:ysairplane/tools/YSNetWorking.dart';
- import 'package:ysairplane/tools/YSTools.dart';
- const APPBAR_SCROLL_OFFSET = 100;
- class YSNews extends StatefulWidget {
- @override
- _YSNewsState createState() => _YSNewsState();
- }
- class _YSNewsState extends State<YSNews> {
- ScrollController _scroll = ScrollController();
- double appBarAlpha = 0;
- double start = 0;
- double number = 0;
- List _titles = [];
- List _lists = [];
- List _heads = [];
- int _selected = 0;
- int _page = 1;
- _onScroll(offset) {
- double alpha = offset / APPBAR_SCROLL_OFFSET;
- if (alpha < 0) {
- alpha = 0;
- } else if (alpha > 1) {
- alpha = 1;
- }
- setState(() {
- appBarAlpha = alpha;
- });
- }
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- _getTitleArrayData();
- _getHeadArrayData();
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: SingleChildScrollView(
- child:Stack(
- children: [
- Container(
- height: MediaQuery.of(context).size.height,
- child: Listener(
- onPointerDown: (PointerDownEvent pointerDownEvent) {
- start = pointerDownEvent.position.dy;
- },
- onPointerMove: (PointerMoveEvent pointerMoveEvent) {
- setState(() {
- number = (pointerMoveEvent.position.dy-start)/5;
- });
- },
- onPointerUp: (PointerUpEvent upEvent) {
- setState(() {
- number = 0;
- });
- },
- child: NotificationListener(
- onNotification: (scrollNotification) {
- if (scrollNotification is ScrollUpdateNotification &&
- scrollNotification.depth == 0) {
- //滚动且是列表滚动的时候
- _onScroll(scrollNotification.metrics.pixels);
- return true;
- }else{
- return false;
- }
- },
- child: EasyRefresh(
- onRefresh: _refreshData,
- onLoad: _loadMore,
- header: MaterialHeader(
- ),
- footer: BezierBounceFooter(
- backgroundColor: Colors.transparent,
- color: Colors.transparent,
- ),
- child: SingleChildScrollView(
- controller: _scroll,
- padding: EdgeInsets.all(0),
- child: Column(
- children: [
- Container(
- height: hsp(360)+number,
- child: Swiper(
- itemBuilder: (BuildContext context, int index) {
- return Container(
- child: CachedNetworkImage(
- imageUrl: '${_heads[index]['cover']}',
- fit: BoxFit.fill,
- )
- );
- },
- itemCount: _heads.length,
- scrollDirection: Axis.horizontal,
- loop: true,
- duration: 300,
- autoplay: true,
- onTap: (index) {
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return YSNewDetail(newId: _heads[index]['id'],);
- }
- )
- );
- },
- pagination: SwiperPagination(
- alignment: Alignment.bottomCenter,
- builder: DotSwiperPaginationBuilder(
- color: Colors.white,
- activeColor: Colors.white,
- size: 5.0,
- activeSize: 10.0
- ),
- ),
- autoplayDisableOnInteraction : true,
- ),
- ),
- Container(
- height: 50,
- color: Colors.white,
- padding: EdgeInsets.only(left: 15,right: 15,top: 20),
- child: ListView.separated(
- scrollDirection: Axis.horizontal,
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- setState(() {
- _selected = index;
- });
- _refreshData();
- },
- child: Container(
- height: 30,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('${_titles[index]['typeName']}',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF007AFF):Color(0xFFCCCCCC),decoration: TextDecoration.none,
- fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),),
- Container(height: 2,width: 20,color: index==_selected?Color(0xFF007AFF):Colors.transparent,)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Container(width: 20,);
- },
- itemCount: _titles.length
- ),
- ),
- Container(
- child: ListView.separated(
- shrinkWrap: true,
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return YSNewDetail(newId: _lists[index]['id'],);
- }
- )
- );
- },
- child: Container(
- color: Colors.white,
- padding: EdgeInsets.all(wsp(30)),
- child: _lists[index]['coverCount']==1?Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Column(
- children: [
- Container(
- width: MediaQuery.of(context).size.width-wsp(350),
- margin: EdgeInsets.only(bottom: hsp(40)),
- child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36))),
- ),
- Row(
- children: [
- Container(
- height: hsp(45),
- padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
- child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
- color: Color(0xFFC5E6FE),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: wsp(15)),
- ),
- Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
- ],
- )
- ],
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- Container(
- height: hsp(200),
- width: wsp(220),
- child: CachedNetworkImage(
- imageUrl: '${_lists[index]['cover']}',
- fit: BoxFit.fill,
- ),
- )
- ],
- ):_lists[index]['coverCount']==0?Column(
- children: [
- Container(
- width: MediaQuery.of(context).size.width-wsp(60),
- margin: EdgeInsets.only(bottom: hsp(40)),
- child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36)),maxLines: 2,),
- ),
- Row(
- children: [
- Container(
- height: hsp(45),
- padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
- child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
- color: Color(0xFFC5E6FE),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: wsp(15)),
- ),
- Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
- ],
- )
- ],
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ):Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: MediaQuery.of(context).size.width-wsp(60),
- child: Text('${_lists[index]['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36)),maxLines: 2,),
- ),
- Container(
- height: hsp(200),
- margin: EdgeInsets.only(top: hsp(30),bottom: hsp(30)),
- child: ListView.separated(
- itemBuilder: (context,indexSub){
- return Container(
- height: 200,
- width: (MediaQuery.of(context).size.width-wsp(100))/3,
- child: CachedNetworkImage(
- imageUrl: '${((_lists[index]['cover'].toString()).split(','))[indexSub]}',
- fit: BoxFit.fill,
- ),
- );
- },
- separatorBuilder: (context,indexSub){
- return Container(
- width: wsp(20),
- color: Colors.white,
- );
- },
- itemCount: (_lists[index]['cover'].toString()).split(',').length,
- padding: EdgeInsets.all(0),
- physics: NeverScrollableScrollPhysics(),
- scrollDirection: Axis.horizontal,
- ),
- width: MediaQuery.of(context).size.width-wsp(60),
- ),
- Row(
- children: [
- Container(
- height: hsp(45),
- padding: EdgeInsets.only(left: wsp(9),right: wsp(9)),
- child: Text('${_lists[index]['labelName']}',style: TextStyle(color: Color(0xFF0081EC),fontSize: zsp(24)),),
- color: Color(0xFFC5E6FE),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: wsp(15)),
- ),
- Text('${_lists[index]['createtime']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
- ],
- )
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Divider(indent: wsp(32),endIndent: wsp(32),height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),);
- },
- itemCount: _lists.length,
- physics: NeverScrollableScrollPhysics(),
- padding: EdgeInsets.only(top: 0.5),
- ),
- decoration: BoxDecoration(
- border: Border(top: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
- ),
- )
- ],
- ),
- ),
- ),
- ),
- ),
- ),
- Container(
- height: MediaQuery.of(context).padding.top+44,
- padding: EdgeInsets.only(left: 15,right: 15,top: MediaQuery.of(context).padding.top),
- color: Colors.white.withOpacity(appBarAlpha),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- GestureDetector(
- onTap: (){
- Navigator.pop(context);
- },
- child: Container(
- alignment: Alignment.centerLeft,
- child: Icon(Icons.arrow_back_ios,size: 20,color: appBarAlpha>0.5?Color(0xFF000000):Colors.white,),
- width: (MediaQuery.of(context).size.width-30)/3,
- )
- ),
- if(appBarAlpha>0.5)Container(
- child: Text('通航头条',style: TextStyle(fontSize: 18,color: Color(0xFF000000),decoration: TextDecoration.none),),
- width: (MediaQuery.of(context).size.width-30)/3,
- ),
- Container(
- width: (MediaQuery.of(context).size.width-30)/3,
- )
- ],
- ),
- )
- ],
- ),
- ),
- );
- }
- _getHeadArrayData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/Carousel/list',parameter: {});
- setState(() {
- _heads = dict['data'];
- });
- }
- _getTitleArrayData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/type/list',parameter: {});
- if(dict!=null){
- setState(() {
- _titles = dict['data']['list'];
- });
- _refreshData();
- }
- }
- Future<void> _refreshData() async{
- _page = 1;
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/list',parameter: {'pageNo':_page,'pageSize':10,'headlineTypeId':_titles[_selected]['id']});
- if(dict!=null){
- setState(() {
- _lists = dict['data']['list'];
- });
- }
- }
- Future<void> _loadMore() async{
- _page++;
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/list',parameter: {'pageNo':_page,'pageSize':10,'headlineTypeId':_titles[_selected]['id']});
- if(dict!=null){
- setState(() {
- _lists.addAll(dict['data']['list']);
- });
- }
- }
- }
|