Commit 14e0a099 authored by ColdPaleLight's avatar ColdPaleLight

add GlobalRouteSettingsManager

parent bf030eb4
......@@ -135,7 +135,7 @@ class BoostContainerState extends NavigatorState {
@override
BoostContainer get widget => super.widget as BoostContainer;
final List<Route<dynamic>> routerHistory = <Route<dynamic>>[];
List<Route<dynamic>> routerHistory = <Route<dynamic>>[];
bool multipleRouteMode = false;
......@@ -163,7 +163,12 @@ class BoostContainerState extends NavigatorState {
@override
void dispose() {
for (Route route in routerHistory) {
GlobalRouteSettingsManager.instance.removeSettings(route);
}
routerHistory.clear();
super.dispose();
}
......@@ -173,6 +178,8 @@ class BoostContainerState extends NavigatorState {
backPressedHandler?.call();
}
Route get topRoute => routerHistory.isNotEmpty ? routerHistory.last : null;
@override
Future<bool> maybePop<T extends Object>([T result]) async {
final Route<T> route = routerHistory.last;
......@@ -197,12 +204,16 @@ class BoostContainerState extends NavigatorState {
@override
bool pop<T extends Object>([T result]) {
Route removedRoute;
if (routerHistory.length > 1) {
routerHistory.removeLast();
removedRoute = routerHistory.removeLast();
}
if (canPop()) {
super.pop<T>(result);
if (removedRoute != null) {
GlobalRouteSettingsManager.instance.removeSettings(removedRoute);
}
if (Platform.isIOS && multipleRouteMode && !canPop()) {
FlutterBoost.singleton.channel
.invokeMethod<dynamic>('enablePopGesture', null);
......@@ -329,3 +340,28 @@ class ContainerNavigatorObserver extends NavigatorObserver {
}
}
}
class GlobalRouteSettingsManager {
GlobalRouteSettingsManager._();
static GlobalRouteSettingsManager instance = GlobalRouteSettingsManager._();
final Map<Route,BoostRouteSettings> _routeSettingsMap = <Route,BoostRouteSettings>{};
void addSettings(Route route,BoostRouteSettings settings) {
_routeSettingsMap[route] = settings;
}
void removeSettings(Route route) {
_routeSettingsMap.remove(route);
}
BoostRouteSettings getSettings(Route route) {
return _routeSettingsMap[route];
}
bool contains(Route route) {
return _routeSettingsMap[route] != null;
}
}
......@@ -51,8 +51,6 @@ typedef void PostPushRoute(String url, String uniqueId, Map params, Route route,
typedef Route FlutterBoostRouteBuilder(Widget widget);
class FlutterBoost {
static final FlutterBoost _instance = FlutterBoost();
final GlobalKey<ContainerManagerState> containerManagerKey =
......@@ -155,39 +153,40 @@ class FlutterBoost {
{Map<String, dynamic> urlParams,
Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) {
final BoostRouteSettings routeSettings = ContainerCoordinator.singleton.createRouteSettings(url,urlParams: urlParams,exts: exts);
final BoostRouteSettings routeSettings = ContainerCoordinator.singleton
.createRouteSettings(url, urlParams: urlParams, exts: exts);
final Widget page = ContainerCoordinator.singleton.createPage(
routeSettings.name, routeSettings.params, routeSettings.uniqueId);
if (page == null ) {
if (page == null) {
return open(url, urlParams: urlParams, exts: exts);
}
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: defaultRoute(page,routeSettings);
: defaultRoute(page, routeSettings);
FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode = true;
GlobalRouteSettingsManager.instance.addSettings(route, routeSettings);
FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode = true;
return FlutterBoost.containerManager?.onstageContainer?.push(route);
}
Route<Map<dynamic, dynamic>> defaultRoute(Widget page,BoostRouteSettings settings ) {
RouteSettings routeSettings =new RouteSettings(name:settings.name,arguments:settings.params);
Route<Map<dynamic, dynamic>> defaultRoute(Widget page,
BoostRouteSettings settings) {
RouteSettings routeSettings = new RouteSettings(
name: settings.name, arguments: settings.params);
if (Platform.isIOS) {
return CupertinoPageRoute<Map<dynamic, dynamic>> (
return CupertinoPageRoute<Map<dynamic, dynamic>>(
settings: routeSettings,
builder: (BuildContext context) => page
);
}
return PageRouteBuilder(
transitionDuration: Duration(milliseconds: 300),
settings:routeSettings ,
settings: routeSettings,
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var offsetAnimation = Tween<Offset>(
......@@ -199,7 +198,6 @@ class FlutterBoost {
child: child,
);
});
}
/**
......@@ -211,9 +209,9 @@ class FlutterBoost {
Future<bool> close(String id,
{Map<String, dynamic> result, Map<String, dynamic> exts}) {
//判断当前onStage的容器是不是通过openInCurrentContainer打开过界面
if (FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode ?? false) {
if (FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode ??
false) {
return Future.value(closeInCurrentContainer(result));
}
......@@ -247,11 +245,8 @@ class FlutterBoost {
properties["exts"] = exts;
}
return channel.invokeMethod<bool>('closePage', properties);
}
Future<bool> closeCurrent(
{Map<String, dynamic> result, Map<String, dynamic> exts}) {
BoostContainerSettings settings = containerManager?.onstageSettings;
......@@ -290,4 +285,16 @@ class FlutterBoost {
///register callbacks for Navigators push & pop
void addBoostNavigatorObserver(NavigatorObserver observer) =>
ContainerNavigatorObserver.boostObservers.add(observer);
BoostRouteSettings getBoostRouteSettings(Route route) {
return GlobalRouteSettingsManager.instance.getSettings(route);
}
BoostRouteSettings getCurrentBoostRouteSettings() {
Route route = FlutterBoost?.containerManager?.onstageContainer?.topRoute;
if (route != null) {
return GlobalRouteSettingsManager.instance.getSettings(route);
}
return null;
}
}
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