Commit 083d23b8 authored by 何碧荣's avatar 何碧荣

发现页提交

parents 64de7666 71a0364e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
//UserRouterImpl is resign : true //UserRouterImpl is resign : true
//WebRouterImpl is resign : true //WebRouterImpl is resign : true
import 'package:gmalpha_flutter/FindModel/FindRouter.dart';
import "package:gmalpha_flutter/MainModel/MainRouterImpl.dart"; import "package:gmalpha_flutter/MainModel/MainRouterImpl.dart";
import "package:gmalpha_flutter/MainModel/MainRouter.dart"; import "package:gmalpha_flutter/MainModel/MainRouter.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedImpl.dart"; import "package:gmalpha_flutter/BuriedLib/BuriedImpl.dart";
...@@ -27,6 +28,8 @@ import "package:gmalpha_flutter/WebModel/WebRouter.dart"; ...@@ -27,6 +28,8 @@ import "package:gmalpha_flutter/WebModel/WebRouter.dart";
import "package:gmalpha_flutter/Annotations/RouterCenterRestore.dart"; import "package:gmalpha_flutter/Annotations/RouterCenterRestore.dart";
import "package:gmalpha_flutter/Annotations/RouterBaser.dart"; import "package:gmalpha_flutter/Annotations/RouterBaser.dart";
class RouterCenterImpl { class RouterCenterImpl {
Map<String, RouterBaser> map; Map<String, RouterBaser> map;
...@@ -77,11 +80,11 @@ class RouterCenterImpl { ...@@ -77,11 +80,11 @@ class RouterCenterImpl {
return map["buried_router"] as BuriedRouter; return map["buried_router"] as BuriedRouter;
} }
AlbumRouter findAlbumRouter() { FindRouter findFindRouter() {
if (map["albumModel"] == null) { if (map["FindModel"] == null) {
return null; return null;
} }
return map["albumModel"] as AlbumRouter; return map["FindModel"] as FindRouter;
} }
NewMessageRouter findNewMessageRouter() { NewMessageRouter findNewMessageRouter() {
......
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/Annotations/RouterBaser.dart';
import 'package:gmalpha_flutter/Annotations/anno/Router.dart';
import 'package:gmalpha_flutter/FindModel/FindRouterImpl.dart';
@Router("FindModel",FindRouterImpl,true)
abstract class FindRouter implements RouterBaser{
Widget getFindPage(String fromPage);
}
\ No newline at end of file
import 'package:flutter/widgets.dart';
import 'package:gmalpha_flutter/FindModel/FindRouter.dart';
import 'package:gmalpha_flutter/FindModel/page/FindPage.dart';
class FindRouterImpl implements FindRouter {
@override
Widget getFindPage(String fromPage) {
return FindPage(fromPage);
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:gmalpha_flutter/FindModel/service/FindRepository.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:gmalpha_flutter/commonModel/live/BaseModel.dart';
import 'package:gmalpha_flutter/commonModel/live/LiveData.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
class FindModel extends BaseModel{
final int page;
final int count;
LiveData<FindEntity> findLive = new LiveData();
FindEntity findList;
FindModel(this.page, this.count);
init(BuildContext context,[callback=null]){
getFindPage(page,count,callback);
}
getFindPage(page,count,[callback]){
FindRepository.getInstance()
.getFindPage(page, count)
.listen((value){
if (value != null) {
if(page > 1) {
findList.data?.cards?.addAll(value.data.cards);
} else {
findList = value;
}
if(callback != null) callback(value);
findLive.notifyView(findList);
}
}).onError((error) {
Toast.show(error, "${error.toString()}");
print(error);
});
}
@override
void dispose() {
findLive.dispost();
}
}
\ No newline at end of file
import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/FindModel/page/FindModel.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/BaseComponent.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class FindPage extends StatefulWidget {
FindModel _findModel;
final String fromPage;
FindPage(this.fromPage) {
_findModel = new FindModel(1, 8);
}
@override
_FindPageState createState() => _FindPageState(_findModel);
}
class _FindPageState extends BasePage<FindPage> {
FindModel _findModel;
static int count = 8;
static int page = 1;
RefreshController _refreshController =
RefreshController(initialRefresh: false);
_FindPageState(this._findModel);
@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil(width: 375.0, height: 667.0)
..init(context);
return Scaffold(
appBar: AppBar(
leading: GestureDetector(
child: Center(
child: Container(
padding: EdgeInsets.fromLTRB(12, 0, 0, 0),
child: Text("发现"),
),
)),
centerTitle: false,
backgroundColor: ALColors.ColorFFFFFF,
actions: <Widget>[
Container(
padding: EdgeInsets.only(right: 16),
child: new Icon(Icons.search , size: 24.0,),
),
],
),
body: SmartRefresher(
enablePullDown: true,
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: CustomScrollView(
slivers: <Widget>[
// SliverToBoxAdapter(
// child: Container(height: 1,
// color: Colors.amberAccent,),
// ),
getListView(),
],
)));
}
void _onRefresh() {
_findModel.init(context, (value) {
Timer(Duration(seconds: 1), () {
_refreshController.refreshToIdle();
});
});
}
void _onLoading() async {
page++;
await _findModel.getFindPage(page, count, (data) {
if (data.data?.cards?.length == 0) {
_refreshController.loadNoData();
} else {
_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(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
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 loadingItem() {
Widget loadCircle = Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 60.0),
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(
left: ScreenUtil.instance.setSp(10),
right: ScreenUtil.instance.setSp(10),
top: ScreenUtil.instance.setSp(10),
bottom: ScreenUtil.instance.setSp(10)),
child: Text('加载中...'),
)
],
);
return SliverFillViewport(delegate: SliverChildListDelegate([loadCircle]));
}
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 loadingItem();
}
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int 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);
}
},
childCount: dataList.cards.length,
));
});
}
Widget noData() {
return Container(
height: double.maxFinite,
width: double.maxFinite,
color: Colors.amberAccent,
);
}
@override
void dispose() {
super.dispose();
_refreshController.dispose();
}
@override
String pageName() {
return 'find_home';
}
@override
String referrer() {
return widget.fromPage;
}
@override
void initState() {
super.initState();
_findModel.init(context);
}
}
import 'package:gmalpha_flutter/FindModel/service/local/FindLocal.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/FindRemote.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:rxdart/rxdart.dart';
class FindRepository {
FindRemote _remote;
FindLocal _local;
static FindRepository _findRepository;
FindRepository._(){
_remote = FindRemote.getInstance();
_local = FindLocal.getInstance();
}
static FindRepository getInstance(){
if(_findRepository == null){
_findRepository = FindRepository._();
}
return _findRepository;
}
Observable<FindEntity> getFindPage(int page, int count){
return _remote.getFindPage(page, count).map((value){
if(value != null){
}
return value;
});
}
}
\ No newline at end of file
class FindLocal {
static FindLocal _findRemote;
FindLocal._(){}
static FindLocal getInstance(){
if(_findRemote == null){
_findRemote = new FindLocal._();
}
return _findRemote;
}
}
\ No newline at end of file
import 'package:gmalpha_flutter/FindModel/service/remote/api/FindApi.serv.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:rxdart/rxdart.dart';
class FindRemote{
static FindRemote _findRemote;
FindRemote._(){}
static FindRemote getInstance(){
if(_findRemote == null){
_findRemote = new FindRemote._();
}
return _findRemote;
}
Observable<FindEntity> getFindPage(int page,int count){
return FindApiImpl().getFindPage(page,count);
}
}
\ No newline at end of file
import 'package:gmalpha_flutter/Annotations/anno/Get.dart';
import 'package:gmalpha_flutter/Annotations/anno/Query.dart';
import 'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
@ServiceCenter()
abstract class FindApi {
@Get("api/v1/discover")
FindEntity getFindPage(@Query('page') int page, @Query('count') int count);
}
\ No newline at end of file
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// ServiceGenerator
// **************************************************************************
import 'dart:convert';
import 'dart:io';
import 'package:rxdart/rxdart.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:gmalpha_flutter/FindModel/service/remote/entity/FindEntity.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
class FindApiImpl {
factory FindApiImpl() => _sharedInstance();
static FindApiImpl _instance;
FindApiImpl._() {}
static FindApiImpl _sharedInstance() {
if (_instance == null) {
_instance = FindApiImpl._();
}
return _instance;
}
Observable<FindEntity> getFindPage(int page, int count) {
return Observable.fromFuture(DioUtil().get('api/v1/discover',
data: {'page': page, 'count': count})).flatMap((value) {
if (value != null && value.statusCode == 200) {
return Observable.fromFuture(compute(paseFindEntity, value.toString()));
} else {
return Observable.fromFuture(null);
}
});
}
}
FindEntity paseFindEntity(String value) {
return FindEntity.fromJson(json.decode(value));
}
class FindEntity {
int error;
String message;
Null extra;
Data data;
FindEntity({this.error, this.message, this.extra, this.data});
FindEntity.fromJson(Map<String, dynamic> json) {
error = json['error'];
message = json['message'];
extra = json['extra'];
data = json['data'] != null ? new Data.fromJson(json['data']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['error'] = this.error;
data['message'] = this.message;
data['extra'] = this.extra;
if (this.data != null) {
data['data'] = this.data.toJson();
}
return data;
}
}
class Data {
List<Cards> cards;
Data({this.cards});
Data.fromJson(Map<String, dynamic> json) {
if (json['cards'] != null) {
cards = new List<Cards>();
json['cards'].forEach((v) {
cards.add(new Cards.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.cards != null) {
data['cards'] = this.cards.map((v) => v.toJson()).toList();
}
return data;
}
}
class Cards {
List<Topics> topics;
int layout;
Cards({this.topics, this.layout});
Cards.fromJson(Map<String, dynamic> json) {
if (json['topics'] != null) {
topics = new List<Topics>();
json['topics'].forEach((v) {
topics.add(new Topics.fromJson(v));
});
}
layout = json['layout'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.topics != null) {
data['topics'] = this.topics.map((v) => v.toJson()).toList();
}
data['layout'] = this.layout;
return data;
}
}
class Topics {
int topicId;
String imageUrl;
int imageId;
Topics({this.topicId, this.imageUrl, this.imageId});
Topics.fromJson(Map<String, dynamic> json) {
topicId = json['topic_id'];
imageUrl = json['image_url'];
imageId = json['image_id'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['topic_id'] = this.topicId;
data['image_url'] = this.imageUrl;
data['image_id'] = this.imageId;
return data;
}
}
\ No newline at end of file
...@@ -32,6 +32,7 @@ class TestPage extends StatelessWidget { ...@@ -32,6 +32,7 @@ class TestPage extends StatelessWidget {
testMessagePage(context), testMessagePage(context),
likePage(context), likePage(context),
focusPage(context), focusPage(context),
findPage(context),
], ],
), ),
)); ));
...@@ -125,4 +126,14 @@ class TestPage extends StatelessWidget { ...@@ -125,4 +126,14 @@ class TestPage extends StatelessWidget {
?.getFocusPage('message_home'))); ?.getFocusPage('message_home')));
}, "关注页面"); }, "关注页面");
} }
findPage(BuildContext context) {
return base(context, () {
Navigator.push(
context,
new CustomRoute(RouterCenterImpl()
.findFindRouter()?.getFindPage('find_home'))
);
}, "发现页面");
}
} }
...@@ -115,7 +115,16 @@ class _MyAppState extends State<MyApp> { ...@@ -115,7 +115,16 @@ class _MyAppState extends State<MyApp> {
return RouterCenterImpl() return RouterCenterImpl()
.findNewMessageRouter() .findNewMessageRouter()
?.getLikePage(params["fromPage"]); ?.getLikePage(params["fromPage"]);
} },
'find_home': (pageName, params, _) {
if (!Api.getInstance().setDioCookie(params) ||
params["fromPage"] == null) {
return ErrorPage("出错:需要传递的参数为空");
}
return RouterCenterImpl()
.findFindRouter()
?.getFindPage(params["fromPage"]);
},
}); });
FlutterBoost.handleOnStartPage(); FlutterBoost.handleOnStartPage();
} }
...@@ -125,11 +134,11 @@ class _MyAppState extends State<MyApp> { ...@@ -125,11 +134,11 @@ class _MyAppState extends State<MyApp> {
return MaterialApp( return MaterialApp(
title: 'Flutter Boost example', title: 'Flutter Boost example',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
// routes: { routes: {
// '/': (context) { '/': (context) {
// return TestPage(); return TestPage();
// }, },
// }, },
builder: buildOnce, builder: buildOnce,
theme: new ThemeData( theme: new ThemeData(
primaryColor: Colors.white, primaryColor: Colors.white,
......
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