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

发现页提交

parents 64de7666 71a0364e
......@@ -11,6 +11,7 @@
//UserRouterImpl 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/MainRouter.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedImpl.dart";
......@@ -27,6 +28,8 @@ import "package:gmalpha_flutter/WebModel/WebRouter.dart";
import "package:gmalpha_flutter/Annotations/RouterCenterRestore.dart";
import "package:gmalpha_flutter/Annotations/RouterBaser.dart";
class RouterCenterImpl {
Map<String, RouterBaser> map;
......@@ -77,11 +80,11 @@ class RouterCenterImpl {
return map["buried_router"] as BuriedRouter;
}
AlbumRouter findAlbumRouter() {
if (map["albumModel"] == null) {
FindRouter findFindRouter() {
if (map["FindModel"] == null) {
return null;
}
return map["albumModel"] as AlbumRouter;
return map["FindModel"] as FindRouter;
}
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
This diff is collapsed.
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 {
testMessagePage(context),
likePage(context),
focusPage(context),
findPage(context),
],
),
));
......@@ -125,4 +126,14 @@ class TestPage extends StatelessWidget {
?.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> {
return RouterCenterImpl()
.findNewMessageRouter()
?.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();
}
......@@ -125,11 +134,11 @@ class _MyAppState extends State<MyApp> {
return MaterialApp(
title: 'Flutter Boost example',
debugShowCheckedModeBanner: false,
// routes: {
// '/': (context) {
// return TestPage();
// },
// },
routes: {
'/': (context) {
return TestPage();
},
},
builder: buildOnce,
theme: new ThemeData(
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