Commit b393b000 authored by Jidong Chen's avatar Jidong Chen

update

parent accabe65
......@@ -2,7 +2,6 @@ PODS:
- Flutter (1.0.0)
- flutter_boost (0.0.1):
- Flutter
- xservice_kit
- xservice_kit (0.0.1):
- Flutter
......@@ -21,7 +20,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_boost: 6a083f2f1b67f9b08724d6c4b280a099d1b40797
flutter_boost: a018687cd20f74f410a6ab17bd33187f5f31f8fd
xservice_kit: a86c64372b3e41e7d8e9b1a0b9139866680f525c
PODFILE CHECKSUM: 2a757a7bdc03b37a2814666652fdff1cf694243f
......
......@@ -128,7 +128,30 @@
- (id<FLB2FlutterProvider>)flutterProvider
{
return _viewProvider;
return (id)_viewProvider;
}
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
[self.platform closePage:uid
animated:[exts[@"animated"] boolValue]
params:exts[@"params"]
completion:completion];
}
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion
{
[self.platform openPage:url
params:urlParams
animated:[exts[@"animated"] boolValue]
completion:completion];
}
@end
......@@ -129,4 +129,19 @@
return self.flutterProvider.engine.viewController;
}
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion{
}
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion{
}
@end
......@@ -33,15 +33,15 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)userBoost2;
@required
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
animated:(BOOL)animated
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(BOOL)animated
completion:(void (^)(BOOL finished))completion;
- (void)closePage:(NSString *)uid
animated:(BOOL)animated
params:(NSDictionary *)params
completion:(void (^)(BOOL finished))completion;
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL finished))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -55,6 +55,20 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resume;
- (void)inactive;
- (BOOL)isRunning;
#pragma mark - handle close/open messages
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion;
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion;
@end
NS_ASSUME_NONNULL_END
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef void (^FLBPageResultHandler)(NSString *, NSDictionary *);
@interface FLBResultMediator : NSObject
- (void)onResultForKey:(NSString *)resultId resultData:(NSDictionary *)resultData params:(NSDictionary *)params;
- (void)setResultHandler:(FLBPageResultHandler)handler forKey:(NSString *)vcid;
- (void)removeHandlerForKey:(NSString *)vcid;
@end
NS_ASSUME_NONNULL_END
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBResultMediator.h"
#import "Service_NavigationService.h"
@interface FLBResultMediator()
@property (nonatomic,strong) NSMutableDictionary *handlers;
@end
@implementation FLBResultMediator
- (instancetype)init
{
if (self = [super init]) {
_handlers = [NSMutableDictionary new];
}
return self;
}
- (void)onResultForKey:(NSString *)rid
resultData:(NSDictionary *)resultData
params:(nonnull NSDictionary *)params
{
if(!rid) return;
NSString *key = rid;
if(_handlers[key]){
FLBPageResultHandler handler = _handlers[key];
handler(key,resultData);
[_handlers removeObjectForKey: key];
}else{
//Cannot find handler here. Try to forward message to flutter.
//Use forward to avoid circle.
if(!params || !params[@"forward"]){
NSMutableDictionary *tmp = params.mutableCopy;
if(!tmp){
tmp = NSMutableDictionary.new;
}
tmp[@"forward"] = @(1);
params = tmp;
[Service_NavigationService onNativePageResult:^(NSNumber *r) {}
uniqueId:rid
key:rid
resultData:resultData
params:params];
}else{
NSMutableDictionary *tmp = params.mutableCopy;
tmp[@"forward"] = @([params[@"forward"] intValue] + 1);
params = tmp;
if([params[@"forward"] intValue] <= 2){
[Service_NavigationService onNativePageResult:^(NSNumber *r) {}
uniqueId:rid
key:rid
resultData:resultData
params:params];
}
}
}
}
- (void)setResultHandler:(FLBPageResultHandler)handler
forKey:(NSString *)vcid
{
if(!handler || !vcid) return;
_handlers[vcid] = handler;
}
- (void)removeHandlerForKey:(NSString *)vcid
{
if(!vcid) return;
[_handlers removeObjectForKey:vcid];
}
@end
......@@ -46,18 +46,4 @@
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name;
#pragma mark - handing vc result.
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion
resultHandler:(void (^)(NSString *resultId,NSDictionary *rData))resultHandler;
- (void)onResultForKey:(NSString *)vcId
resultData:(NSDictionary *)resultData
params:(NSDictionary *)params;
- (void)setResultHandler:(void (^)(NSString *, NSDictionary *))handler
forKey:(NSString *)result_id;
- (void)removeHandlerForKey:(NSString *)vcid;
@end
......@@ -23,7 +23,6 @@
*/
#import "FlutterBoostPlugin.h"
#import "FLBResultMediator.h"
#import "FlutterBoostPlugin_private.h"
#import "FLBFactory.h"
#import "FLB2Factory.h"
......@@ -97,7 +96,6 @@
- (instancetype)init
{
if (self = [super init]) {
_resultMediator = [FLBResultMediator new];
_dispatcher = FLBMessageDispather.new;
}
......@@ -109,10 +107,6 @@
return _application;
}
- (FLBResultMediator *)resultMediator
{
return _resultMediator;
}
- (id<FLBAbstractFactory>)factory
{
......@@ -149,32 +143,6 @@
return [self.application flutterViewController];
}
- (void)openPage:(NSString *)name
params:(NSDictionary *)params animated:(BOOL)animated
completion:(void (^)(BOOL))completion
resultHandler:(void (^)(NSString *, NSDictionary *))resultHandler
{
static int kRid = 0;
NSString *resultId = [NSString stringWithFormat:@"result_id_%d",kRid++];
[_resultMediator setResultHandler:^(NSString * _Nonnull resultId, NSDictionary * _Nonnull resultData) {
if(resultHandler) resultHandler(resultId,resultData);
} forKey:resultId];
}
- (void)onResultForKey:(NSString *)vcId resultData:(NSDictionary *)resultData params:(NSDictionary *)params
{
[_resultMediator onResultForKey:vcId resultData:resultData params:params];
}
- (void)setResultHandler:(void (^)(NSString *, NSDictionary *))handler forKey:(NSString *)vcid
{
[_resultMediator setResultHandler:handler forKey:vcid];
}
- (void)removeHandlerForKey:(NSString *)vcid
{
[_resultMediator removeHandlerForKey:vcid];
}
#pragma mark - broadcast event to/from flutter
- (void)sendEvent:(NSString *)eventName
......@@ -187,7 +155,7 @@
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name
{
[_broadcastor addEventListener:listner
return [_broadcastor addEventListener:listner
forName:name];
}
......
......@@ -24,17 +24,14 @@
#import <Flutter/Flutter.h>
#import "FLBFlutterApplicationInterface.h"
#import "FLBResultMediator.h"
#import "FLBAbstractFactory.h"
@interface FlutterBoostPlugin(){
id<FLBFlutterApplicationInterface> _application;
FLBResultMediator *_resultMediator;
id<FLBAbstractFactory> _factory;
}
- (id<FLBFlutterApplicationInterface>)application;
- (FLBResultMediator *)resultMediator;
- (id<FLBAbstractFactory>)factory;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
......
......@@ -30,31 +30,18 @@
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
@implementation NavigationService_closePage
- (void)onCall:(void (^)(BOOL))result
uniqueId:(NSString *)uniqueId
pageName:(NSString *)pageName
params:(NSDictionary *)params
animated:(NSNumber *)animated
{
//Add your handler code here!
[FLUTTER_APP.platform closePage:uniqueId
animated:animated.boolValue
params:params
completion:^(BOOL finished) {
if(result) result(finished);
}];
}
#pragma mark - Do not edit these method.
- (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
- (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))resultBlock
{
NSDictionary *args = msg.params;
[self onCall:result
uniqueId:args[@"uniqueId"]
pageName:args[@"pageName"]
params:args[@"params"]
animated:args[@"animated"]];
NSDictionary *exts = args[@"exts"];
NSString *uid = args[@"uniqueId"];
NSDictionary *resultData = args[@"result"];
[FLUTTER_APP close:uid
result:resultData
exts:exts
completion:resultBlock];
return YES;
}
......
......@@ -32,10 +32,7 @@
- (void)onCall:(void (^)(BOOL))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params
{
//Add your handler code here!
[FlutterBoostPlugin.sharedInstance onResultForKey:key
resultData:resultData
params:params];
}
#pragma mark - Do not edit these method.
......
......@@ -32,28 +32,24 @@
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
@implementation NavigationService_openPage
- (void)onCall:(void (^)(BOOL))result pageName:(NSString *)pageName params:(NSDictionary *)params animated:(NSNumber *)animated
{
[FLUTTER_APP.platform openPage:pageName
params:params
animated:animated.boolValue
completion:^(BOOL finished) {
if(result)result(YES);
}];
}
#pragma mark - Do not edit these method.
- (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result{
- (BOOL)call:(id<FLBMessage>)msg result:(void (^)(NSDictionary *))result{
NSDictionary *args = msg.params;
[self onCall:result pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]];
NSString *url = args[@"url"];
NSDictionary *urlParams = args[@"urlParams"];
NSDictionary *exts = args[@"exts"];
[FLUTTER_APP open:url
urlParams:urlParams
exts:exts
reult:result
completion:^(BOOL) {}];
return YES;
}
- (NSString *)returnType
{
return @"BOOL";
return @"NSDictionary *";
}
- (NSArray *)handledMessageNames
......
......@@ -55,43 +55,16 @@ typedef void PostPushRoute(
String pageName, String uniqueId, Map params, Route route, Future result);
class FlutterBoost {
static final FlutterBoost _instance = FlutterBoost();
final GlobalKey<ContainerManagerState> containerManagerKey =
GlobalKey<ContainerManagerState>();
final ObserversHolder _observersHolder = ObserversHolder();
final PageResultMediator _resultMediator = PageResultMediator();
final Router _router = Router();
final MethodChannel _methodChannel = MethodChannel('flutter_boost');
final MessageDispatcher _dispatcher = MessageDispatcher();
Broadcastor _broadcastor;
FlutterBoost() {
_router.resultMediator = _resultMediator;
_broadcastor = Broadcastor(_methodChannel);
//Config message handlers
NavigationService.methodChannel = _methodChannel;
_dispatcher.registerHandler(DidDisappearPageContainerHandler());
_dispatcher.registerHandler(DidInitPageContainerHandler());
_dispatcher.registerHandler(DidShowPageContainerHandler());
_dispatcher.registerHandler(OnNativePageResultHandler());
_dispatcher.registerHandler(WillDeallocPageContainerHandler());
_dispatcher.registerHandler(WillShowPageContainerHandler());
_dispatcher.registerHandler(WillDisappearPageContainerHandler());
_methodChannel.setMethodCallHandler((MethodCall call){
if(call.method == "__event__"){
//Handler broadcast event.
return _broadcastor.handleCall(call);
}else{
return _dispatcher.dispatch(call);
}
});
}
Broadcastor _broadcastor;
static FlutterBoost get singleton => _instance;
......@@ -100,8 +73,8 @@ class FlutterBoost {
static TransitionBuilder init(
{TransitionBuilder builder,
PrePushRoute prePush,
PostPushRoute postPush}) {
PrePushRoute prePush,
PostPushRoute postPush}) {
return (BuildContext context, Widget child) {
assert(child is Navigator, 'child must be Navigator, what is wrong?');
......@@ -123,6 +96,31 @@ class FlutterBoost {
ObserversHolder get observersHolder => _observersHolder;
FlutterBoost() {
_broadcastor = Broadcastor(_methodChannel);
//Config message handlers
NavigationService.methodChannel = _methodChannel;
_dispatcher.registerHandler(DidDisappearPageContainerHandler());
_dispatcher.registerHandler(DidInitPageContainerHandler());
_dispatcher.registerHandler(DidShowPageContainerHandler());
_dispatcher.registerHandler(OnNativePageResultHandler());
_dispatcher.registerHandler(WillDeallocPageContainerHandler());
_dispatcher.registerHandler(WillShowPageContainerHandler());
_dispatcher.registerHandler(WillDisappearPageContainerHandler());
_methodChannel.setMethodCallHandler((MethodCall call){
if(call.method == "__event__"){
//Handler broadcast event.
return _broadcastor.handleCall(call);
}else{
return _dispatcher.dispatch(call);
}
});
}
///Register a default page builder.
void registerDefaultPageBuilder(PageBuilder builder) {
ContainerCoordinator.singleton.registerDefaultPageBuilder(builder);
......@@ -133,17 +131,52 @@ class FlutterBoost {
ContainerCoordinator.singleton.registerPageBuilders(builders);
}
Future<bool> openPage(String name, Map params,
{bool animated, PageResultHandler resultHandler}) {
return _router.openPage(name, params,
animated: animated, resultHandler: resultHandler);
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return _router.open(url,urlParams: urlParams,exts: exts);
}
Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return _router.close(id,result: result,exts: exts);
}
Future<bool> closePage(String name, String pageId, Map params,
//Listen broadcast event from native.
Function addEventListener(String name , EventListener listener){
return _broadcastor.addEventListener(name, listener);
}
//Send broadcast event to native.
void sendEvent(String name , Map arguments){
_broadcastor.sendEvent(name, arguments);
}
Future<bool> openPage(String name, Map params,{bool animated}) {
Map<String,dynamic> exts = Map();
if(animated != null){
exts["animated"] = animated;
}
return open(name,urlParams: params , exts: exts);
}
Future<bool> closePage(String url, String id, Map params,
{bool animated}) {
return _router.closePage(name, pageId, params, animated: animated);
Map<String,dynamic> exts = Map();
if(animated != null){
exts["animated"] = animated;
}
if(name != null){
exts["url"] = url;
}
if(params != null){
exts["params"] = params;
}
close(id, result: {} , exts: exts);
}
//Close currentPage page.
Future<bool> closeCurPage(Map params) {
return _router.closeCurPage(params);
......@@ -170,21 +203,6 @@ class FlutterBoost {
}
bool onPageResult(String key, Map resultData, Map params) {
if(_resultMediator.isResultId(key)){
_resultMediator.onPageResult(key, resultData,params);
}else{
containerManager?.containerStateOf(key)?.performOnResult(resultData);
}
return true;
}
VoidCallback setPageResultHandler(String key, PageResultHandler handler) {
return _resultMediator.setPageResultHandler(key, handler);
}
///register for Container changed callbacks
VoidCallback addContainerObserver(BoostContainerObserver observer) =>
_observersHolder.addObserver<BoostContainerObserver>(observer);
......@@ -199,13 +217,4 @@ class FlutterBoost {
_observersHolder.addObserver<BoostNavigatorObserver>(observer);
//Listen broadcast event from native.
Function addEventListener(String name , EventListener listener){
return _broadcastor.addEventListener(name, listener);
}
//Send broadcast event to native.
void sendEvent(String name , Map arguments){
_broadcastor.sendEvent(name, arguments);
}
}
......@@ -24,7 +24,6 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/messaging/base/message_handler.dart';
......@@ -42,6 +41,5 @@ class OnNativePageResultHandler implements MessageHandler {
//==============================================Do not edit code above!
Future<bool> onCall(String uniqueId,String key,Map resultData,Map params) async{
return FlutterBoost.singleton.onPageResult(key, resultData, params);
}
}
......@@ -25,19 +25,23 @@ import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'dart:async';
abstract class MessageProxy{
Future<bool> openPage(String pageName,Map params,bool animated);
Future<bool> closePage(String uniqueId,String pageName,Map params,bool animated);
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts});
void close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts});
}
class MessageProxyImp implements MessageProxy{
@override
Future<bool> openPage(String pageName, Map params, bool animated) {
return NavigationService.openPage(pageName, params, animated);
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return NavigationService.openPage(url, urlParams, exts);
}
@override
Future<bool> closePage(String uniqueId, String pageName, Map params, bool animated) {
return NavigationService.closePage(uniqueId, pageName, params, animated);
void close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return NavigationService.closePage(uniqueId,result: result,exts: exts);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'package:flutter_boost/support/logger.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
typedef void PageResultHandler(String key , Map<String,dynamic> result);
typedef VoidCallback = void Function();
class PageResultMediator{
static int _resultId = 0;
String createResultId(){
_resultId++;
return "result_id_$_resultId";
}
bool isResultId(String rid){
if(rid == null) return false;
return rid.contains("result_id");
}
Map<String,PageResultHandler> _handlers = Map();
void onPageResult(String key , Map<String,dynamic> resultData, Map params){
if(key == null) return;
Logger.log("did receive page result $resultData for page key $key");
if(_handlers.containsKey(key)){
_handlers[key](key,resultData);
_handlers.remove(key);
}else{
//Cannot find handler consider forward to native.
//Use forward to avoid circle.
if(params == null || !params.containsKey("forward")){
if(params == null){
params = new Map();
}
params["forward"] = 1;
NavigationService.onFlutterPageResult(key, key , resultData, params);
}else{
params["forward"] = params["forward"]+1;
if(params["forward"] <= 2){
NavigationService.onFlutterPageResult(key, key , resultData, params);
}
}
}
}
VoidCallback setPageResultHandler(String key, PageResultHandler handler){
if(key == null || handler == null) return (){};
_handlers[key] = handler;
return (){
_handlers.remove(key);
};
}
}
......@@ -61,23 +61,29 @@ class NavigationService {
return Future<Map>((){});
}
}
static Future<bool> openPage(String pageName,Map params,bool animated) {
static Future<Map<String,dynamic>> openPage(String url,Map urlParams, Map exts) {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["pageName"]=pageName;
properties["params"]=params;
properties["animated"]=animated;
return methodChannel.invokeMethod('openPage',properties).then<bool>((value){
properties["url"]=url;
properties["urlParams"]=params;
properties["exts"]=exts;
return methodChannel.invokeMethod('openPage',properties).then<Map<String,dynamic>>((value){
return (value);
});
}
static Future<bool> closePage(String uniqueId,String pageName,Map params,bool animated) {
static Future<bool> closePage(String uniqueId,{Map<String,dynamic> result,Map<String,dynamic> exts}) {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["uniqueId"]=uniqueId;
properties["pageName"]=pageName;
properties["params"]=params;
properties["animated"]=animated;
return methodChannel.invokeMethod('closePage',properties).then<bool>((value){
return value;
if(result != null){
properties["result"]=result;
}
if(exts != null) {
properties["exts"] = exts;
}
return methodChannel.invokeMethod('closePage',properties).then<bool>((value){
return value;
});
}
}
\ No newline at end of file
......@@ -31,8 +31,6 @@ import 'package:flutter_boost/support/logger.dart';
class Router {
MessageProxy _msgProxy = MessageProxyImp();
PageResultMediator resultMediator = null;
void setMessageProxy(MessageProxy prx) {
if (prx != null) {
......@@ -41,28 +39,15 @@ class Router {
}
Future<bool> openPage(String url, Map params,
{bool animated = true, PageResultHandler resultHandler}) {
if (resultHandler != null) {
String rid = resultMediator.createResultId();
params["result_id"] = rid;
FlutterBoost.singleton.setPageResultHandler(rid,
(String key, Map<dynamic, dynamic> result) {
Logger.log("Recieved result $result for from page key $key");
if (resultHandler != null) {
resultHandler(key, result);
}
});
}
return _msgProxy.openPage(url, params, animated);
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return _msgProxy.open(url,urlParams: urlParams,exts: exts);
}
Future<bool> closePage(String name, String pageId, Map params,
{bool animated = true}) {
return _msgProxy.closePage(pageId, name, params, animated);
Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return _msgProxy.close(id,result:result,exts: exts);
}
//Close currentPage page.
Future<bool> closeCurPage(Map params) {
BoostContainerSettings settings;
......@@ -87,7 +72,9 @@ class Router {
animated = params["animated"] as bool;
}
return _msgProxy.closePage(
settings.uniqueId, settings.name, settings.params, animated);
Map<String,dynamic> exts = Map();
exts["animated"] = animated;
return _msgProxy.close(id,result: {} ,exts: exts);
}
}
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