Commit b1b34f72 authored by Jidong Chen's avatar Jidong Chen

remove dart code xservice dependency

parent 7b58b614
/*
* 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 'NavigationService.dart';
import '../handlers/NavigationService_onNativePageResult.dart';
import '../handlers/NavigationService_didShowPageContainer.dart';
import '../handlers/NavigationService_willShowPageContainer.dart';
import '../handlers/NavigationService_willDisappearPageContainer.dart';
import '../handlers/NavigationService_didDisappearPageContainer.dart';
import '../handlers/NavigationService_didInitPageContainer.dart';
import '../handlers/NavigationService_willDeallocPageContainer.dart';
class NavigationServiceRegister{
static register(){
NavigationService.regsiter();
NavigationService_onNativePageResult.regsiter();
NavigationService_didShowPageContainer.regsiter();
NavigationService_willShowPageContainer.regsiter();
NavigationService_willDisappearPageContainer.regsiter();
NavigationService_didDisappearPageContainer.regsiter();
NavigationService_didInitPageContainer.regsiter();
NavigationService_willDeallocPageContainer.regsiter();
}
}
\ No newline at end of file
......@@ -24,7 +24,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/messaging/native_page_container_event_handler.dart';
......@@ -88,7 +88,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler {
void onChannelEvent(dynamic event) {
if (event is Map) {
Map map = event as Map;
Map map = event;
final String type = map['type'];
switch (type) {
......@@ -177,7 +177,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler {
FlutterBoost.containerManager?.remove(pageId);
Logger.log(
'native containner dealloc, \nmanager dump:\n${FlutterBoost.containerManager?.dump()}');
'native containner dealloc, \n manager dump:\n${FlutterBoost.containerManager?.dump()}');
return true;
}
......
......@@ -23,7 +23,7 @@
*/
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:flutter_boost/flutter_boost.dart';
......
......@@ -24,19 +24,26 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/container/container_manager.dart';
import 'package:flutter_boost/messaging/page_result_mediator.dart';
import 'package:flutter_boost/router/router.dart';
import 'AIOService/loader/ServiceLoader.dart';
import 'container/container_coordinator.dart';
import 'messaging/base/message_dispatcher.dart';
import 'messaging/handlers/did_disappear_page_container_handler.dart';
import 'messaging/handlers/did_show_page_container_handler.dart';
import 'messaging/handlers/did_init_page_container_handler.dart';
import 'messaging/handlers/on_native_page_result_handler.dart';
import 'messaging/handlers/will_dealloc_page_container_handler.dart';
import 'messaging/handlers/will_show_page_container_handler.dart';
import 'messaging/handlers/will_disappear_page_container_handler.dart';
import 'observers_holders.dart';
export 'container/boost_container.dart';
export 'container/container_manager.dart';
import 'package:flutter/services.dart';
typedef Widget PageBuilder(String pageName, Map params, String uniqueId);
......@@ -55,9 +62,25 @@ class FlutterBoost {
final PageResultMediator _resultMediator = PageResultMediator();
final Router _router = Router();
final MethodChannel _methodChannel = MethodChannel('flutter_boost');
final MessageDispatcher _dispatcher = MessageDispatcher();
FlutterBoost() {
_router.resultMediator = _resultMediator;
ServiceLoader.load();
//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){
_dispatcher.dispatch(call);
});
}
static FlutterBoost get singleton => _instance;
......
/*
* 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 'dart:async';
import 'package:flutter/services.dart';
import 'message_handler.dart';
class MessageDispatcher{
Map<String,MessageHandler> _handlers = Map();
Future<dynamic> dispatch(MethodCall call){
if(_handlers.containsKey(call.method)){
return _handlers[call.method].onMethodCall(call);
}{
return null;
}
}
void registerHandler(MessageHandler handler){
_handlers[handler.name()] = handler;
}
}
......@@ -22,12 +22,10 @@
* THE SOFTWARE.
*/
import '../NavigationService/service/NavigationServiceRegister.dart';
import 'dart:async';
import 'package:flutter/services.dart';
class ServiceLoader{
static load(){
NavigationServiceRegister.register();
}
}
\ No newline at end of file
abstract class MessageHandler{
String name();
Future<dynamic> onMethodCall(MethodCall call);
}
\ No newline at end of file
......@@ -25,24 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/messaging/base/message_handler.dart';
class NavigationService_didDisappearPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didDisappearPageContainer());
}
class DidDisappearPageContainerHandler implements MessageHandler {
@override
String name() {
return "didDisappearPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
......
......@@ -24,14 +24,14 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
class NavigationService_didInitPageContainer extends ServiceCallHandler {
import 'package:flutter_boost/messaging/base/message_handler.dart';
class DidInitPageContainerHandler implements MessageHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didInitPageContainer());
// ServiceGateway.sharedInstance()
// .registerHandler(new NavigationService_didInitPageContainer());
}
@override
......@@ -39,10 +39,6 @@ class NavigationService_didInitPageContainer extends ServiceCallHandler {
return "didInitPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
......
......@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/messaging/base/message_handler.dart';
class NavigationService_didShowPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didShowPageContainer());
}
class DidShowPageContainerHandler implements MessageHandler {
@override
String name() {
return "didShowPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"],
......
......@@ -24,26 +24,17 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/flutter_boost.dart';
class NavigationService_onNativePageResult extends ServiceCallHandler {
import 'package:flutter_boost/messaging/base/message_handler.dart';
static void regsiter() {
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onNativePageResult());
}
class OnNativePageResultHandler implements MessageHandler {
@override
String name() {
return "onNativePageResult";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["uniqueId"],call.arguments["key"],call.arguments["resultData"],call.arguments["params"]);
......
......@@ -25,25 +25,14 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_willDeallocPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willDeallocPageContainer());
}
import 'package:flutter_boost/messaging/base/message_handler.dart';
class WillDeallocPageContainerHandler implements MessageHandler {
@override
String name() {
return "willDeallocPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"],
......
......@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/messaging/base/message_handler.dart';
class NavigationService_willDisappearPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willDisappearPageContainer());
}
class WillDisappearPageContainerHandler implements MessageHandler {
@override
String name() {
return "willDisappearPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"],
......
......@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/messaging/base/message_handler.dart';
class NavigationService_willShowPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willShowPageContainer());
}
class WillShowPageContainerHandler implements MessageHandler {
@override
String name() {
return "willShowPageContainer";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"],
......
......@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'dart:async';
abstract class MessageProxy{
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
import 'package:flutter_boost/support/logger.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
typedef void PageResultHandler(String key , Map<String,dynamic> result);
typedef VoidCallback = void Function();
......
......@@ -22,34 +22,30 @@
* THE SOFTWARE.
*/
import 'dart:async';
import 'package:xservice_kit/foundation_ext/foundation_ext.dart';
import 'package:xservice_kit/ServiceTemplate.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'dart:async';
import 'package:flutter/services.dart';
class NavigationService {
static final ServiceTemplate _service =
new ServiceTemplate("NavigationService");
class NavigationService {
static MethodChannel methodChannel;
static void regsiter() {
ServiceGateway.sharedInstance().registerService(_service);
}
//List event from event channel.
static int listenEvent(void onData(dynamic event)) {
return _service.listenEvent(onData);
// return _service.listenEvent(onData);
}
//Cancel event for subscription with ID.
static void cancelEventForSubscription(int subID) {
_service.cancelEventForSubscription(subID);
// _service.cancelEventForSubscription(subID);
}
static Future<bool> onShownContainerChanged(String newName,String oldName,Map params) {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["newName"]=newName;
properties["oldName"]=oldName;
properties["params"]=params;
return _service.methodChannel().invokeMethod('onShownContainerChanged',properties).then<bool>((value){
return BOOL(value);
return methodChannel.invokeMethod('onShownContainerChanged',properties).then<bool>((value){
return (value);
});
}
static Future<bool> onFlutterPageResult(String uniqueId,String key,Map resultData,Map params) {
......@@ -58,15 +54,15 @@
properties["key"]=key;
properties["resultData"]=resultData;
properties["params"]=params;
return _service.methodChannel().invokeMethod('onFlutterPageResult',properties).then<bool>((value){
return BOOL(value);
return methodChannel.invokeMethod('onFlutterPageResult',properties).then<bool>((value){
return (value);
});
}
static Future<Map> pageOnStart(Map params) async {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["params"]=params;
try {
return await _service.methodChannel().invokeMethod('pageOnStart',properties).then<Map>((value){
return await methodChannel.invokeMethod('pageOnStart',properties).then<Map>((value){
return value as Map;
});
} catch (e) {
......@@ -79,8 +75,8 @@
properties["pageName"]=pageName;
properties["params"]=params;
properties["animated"]=animated;
return _service.methodChannel().invokeMethod('openPage',properties).then<bool>((value){
return BOOL(value);
return methodChannel.invokeMethod('openPage',properties).then<bool>((value){
return (value);
});
}
static Future<bool> closePage(String uniqueId,String pageName,Map params,bool animated) {
......@@ -89,8 +85,8 @@
properties["pageName"]=pageName;
properties["params"]=params;
properties["animated"]=animated;
return _service.methodChannel().invokeMethod('closePage',properties).then<bool>((value){
return BOOL(value);
return methodChannel.invokeMethod('closePage',properties).then<bool>((value){
return value;
});
}
}
\ No newline at end of file
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