Commit 070cfffe authored by 何碧荣's avatar 何碧荣

发现页

parent b60f94e8
...@@ -21,14 +21,15 @@ class FindModel extends BaseModel{ ...@@ -21,14 +21,15 @@ class FindModel extends BaseModel{
FindRepository.getInstance() FindRepository.getInstance()
.getFindPage(page, count) .getFindPage(page, count)
.listen((value){ .listen((value){
if(value != null){ if (value != null) {
findList.data.cards?.addAll(value.data.cards); if(page > 1) {
findList.data?.cards?.addAll(value.data.cards);
} else {
findList = value;
}
if(callback != null) callback(value);
findLive.notifyView(findList);
} }
else{
findList = value;
}
if(callback !=null) callback(value);
findLive.notifyView(findList);
}).onError((error) { }).onError((error) {
Toast.show(error, "${error.toString()}"); Toast.show(error, "${error.toString()}");
print(error); print(error);
......
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/FindModel/page/FindModel.dart'; import 'package:gmalpha_flutter/FindModel/page/FindModel.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/messagePage/common.dart'; import 'package:gmalpha_flutter/NewMessageModel/page/messagePage/common.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart'; import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart'; import 'package:gmalpha_flutter/res/value/ALColors.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
class FindPage extends StatefulWidget { class FindPage extends StatefulWidget {
FindModel _findModel; FindModel _findModel;
...@@ -22,7 +25,8 @@ class _FindPageState extends BasePage<FindPage> { ...@@ -22,7 +25,8 @@ class _FindPageState extends BasePage<FindPage> {
FindModel _findModel; FindModel _findModel;
static int count = 8; static int count = 8;
static int page = 1; static int page = 1;
ScrollController _scrollController = new ScrollController();
RefreshController _refreshController = RefreshController(initialRefresh: false);
_FindPageState(this._findModel); _FindPageState(this._findModel);
@override @override
...@@ -36,35 +40,217 @@ class _FindPageState extends BasePage<FindPage> { ...@@ -36,35 +40,217 @@ class _FindPageState extends BasePage<FindPage> {
elevation: 0, elevation: 0,
backgroundColor: ALColors.ColorFFFFFF, backgroundColor: ALColors.ColorFFFFFF,
), ),
body: new Padding( body: SmartRefresher(
padding: const EdgeInsets.only(top: 0.0), enablePullDown: true,
child: listItemInfo(), enablePullUp: true,
header: WaterDropHeader(),
footer: CustomFooter(
builder: (BuildContext context,LoadStatus mode){
Widget body ;
if(mode==LoadStatus.idle){
body = Text("上拉加载");
}
else if(mode==LoadStatus.loading){
body = CupertinoActivityIndicator();
}
else if(mode == LoadStatus.failed){
body = Text("加载失败!点击重试!");
}
else if(mode == LoadStatus.canLoading){
body = Text("松手,加载更多!");
}
else{
body = Text("没有更多数据了!");
}
return Container(
height: 55.0,
child: Center(child:body),
);
},
),
controller: _refreshController,
onRefresh: _onRefresh,
onLoading: _onLoading,
child: getListView(),
)); ));
} }
Widget listItemInfo() { void _onRefresh() async{
return new StaggeredGridView.countBuilder( _findModel.init(context);
controller: _scrollController, await Future.delayed(Duration(milliseconds: 1000));
crossAxisCount: 4, _refreshController.loadComplete();
itemCount: 20, }
itemBuilder: (BuildContext context, int index) => new Container(
color: Colors.green, void _onLoading() async {
child: new Center( await _findModel.getFindPage(page, count, (data) {
child: new CircleAvatar( if(data.data?.cards?.length == 0) {
backgroundColor: Colors.white, _refreshController.loadNoData();
child: new Text('$index'), } else {
page++;
_refreshController.loadComplete();
}
});
}
Widget _listViewUI2(BuildContext context,Cards item) {
return Container(
width: ScreenUtil.instance.setWidth(375.0),
margin: EdgeInsets.only(bottom: ScreenUtil.instance.setHeight(3)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(right: ScreenUtil.instance.setWidth(3.0)),
child: CachedNetworkImage(
imageUrl: '${item.topics[0].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
Container(
margin: EdgeInsets.only(right: ScreenUtil.instance.setWidth(3.0)),
child: CachedNetworkImage(
imageUrl: '${item.topics[1].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
Container(
child: CachedNetworkImage(
imageUrl: '${item.topics[2].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
]
)
);
}
Widget _listViewUI1(BuildContext context,Cards item) {
return Container(
width: ScreenUtil.instance.setWidth(375.0),
margin: EdgeInsets.only(bottom: ScreenUtil.instance.setHeight(3)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(right: ScreenUtil.instance.setWidth(3.0)),
child: CachedNetworkImage(
imageUrl: '${item.topics[0].imageUrl}',
width: ScreenUtil.instance.setWidth(249),
height: ScreenUtil.instance.setHeight(249),
fit: BoxFit.fitHeight,
)
), ),
)), Column(
staggeredTileBuilder: (int index) => crossAxisAlignment: CrossAxisAlignment.start,
new StaggeredTile.count(2, index.isEven ? 2 : 1), children: <Widget>[
mainAxisSpacing: 4.0, Container(
crossAxisSpacing: 4.0, margin: EdgeInsets.only(bottom: ScreenUtil.instance.setHeight(3.0)),
child: CachedNetworkImage(
imageUrl: '${item.topics[1].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)
),
Container(
child: CachedNetworkImage(
imageUrl: '${item.topics[2].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
]
),
]
)
);
}
Widget _listViewUI3(BuildContext context,Cards item) {
return Container(
width: ScreenUtil.instance.setWidth(375.0),
margin: EdgeInsets.only(bottom: ScreenUtil.instance.setHeight(3)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: ScreenUtil.instance.setHeight(3)),
child: CachedNetworkImage(
imageUrl: '${item.topics[0].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
Container(
child: CachedNetworkImage(
imageUrl: '${item.topics[1].imageUrl}',
width: ScreenUtil.instance.setWidth(123),
height: ScreenUtil.instance.setHeight(123),
fit: BoxFit.cover,
)),
]
),
Container(
margin: EdgeInsets.only(left: ScreenUtil.instance.setWidth(3.0)),
child: CachedNetworkImage(
imageUrl: '${item.topics[2].imageUrl}',
width: ScreenUtil.instance.setWidth(249),
height: ScreenUtil.instance.setHeight(249),
fit: BoxFit.cover,
)),
]
)
);
}
Widget getListView() {
return StreamBuilder<FindEntity>(
stream: _findModel.findLive.stream,
initialData: _findModel.findLive.data,
builder: (BuildContext context, data) {
var dataList = data?.data?.data;
if(dataList == null) {
return noData();
}
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
var item = dataList.cards[index];
if(item.layout == 1){
return _listViewUI1(context, item);
}
else if(item.layout == 2){
return _listViewUI2(context, item);
}
else{
return _listViewUI3(context, item);
}
},
itemCount: dataList.cards.length,
);
}
); );
} }
Widget noData() {
return Container();
}
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
_refreshController.dispose();
} }
@override @override
...@@ -76,4 +262,12 @@ class _FindPageState extends BasePage<FindPage> { ...@@ -76,4 +262,12 @@ class _FindPageState extends BasePage<FindPage> {
String referrer() { String referrer() {
return widget.fromPage; return widget.fromPage;
} }
@override
void initState() {
super.initState();
_findModel.init(context);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment