Commit 5740f8d9 authored by ColdPaleLight's avatar ColdPaleLight

support close page without close container

parent e26ead11
...@@ -135,6 +135,8 @@ class BoostContainerState extends NavigatorState { ...@@ -135,6 +135,8 @@ class BoostContainerState extends NavigatorState {
final List<Route<dynamic>> routerHistory = <Route<dynamic>>[]; final List<Route<dynamic>> routerHistory = <Route<dynamic>>[];
bool multipleRouteMode = false;
ContainerNavigatorObserver findContainerNavigatorObserver( ContainerNavigatorObserver findContainerNavigatorObserver(
Navigator navigator) { Navigator navigator) {
for (NavigatorObserver observer in navigator.observers) { for (NavigatorObserver observer in navigator.observers) {
...@@ -202,9 +204,9 @@ class BoostContainerState extends NavigatorState { ...@@ -202,9 +204,9 @@ class BoostContainerState extends NavigatorState {
} else { } else {
if (T is Map<String, dynamic>) { if (T is Map<String, dynamic>) {
FlutterBoost.singleton FlutterBoost.singleton
.close(uniqueId, result: result as Map<String, dynamic>); .closeInternal(uniqueId, result: result as Map<String, dynamic>);
} else { } else {
FlutterBoost.singleton.close(uniqueId); FlutterBoost.singleton.closeInternal(uniqueId,);
} }
} }
return true; return true;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'container/boost_container.dart'; import 'container/boost_container.dart';
import 'container/container_coordinator.dart'; import 'container/container_coordinator.dart';
...@@ -144,9 +145,9 @@ class FlutterBoost { ...@@ -144,9 +145,9 @@ class FlutterBoost {
Map<String, dynamic> exts, Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) { FlutterBoostRouteBuilder routeBuilder}) {
if(!ContainerCoordinator.singleton.isFlutterPageUrl(url)){ // if(!ContainerCoordinator.singleton.isFlutterPageUrl(url)){
return open(url, urlParams: urlParams, exts: exts); // return open(url, urlParams: urlParams, exts: exts);
} // }
String uniqueId='${url}_${DateTime.now().millisecondsSinceEpoch}'; String uniqueId='${url}_${DateTime.now().millisecondsSinceEpoch}';
...@@ -155,18 +156,32 @@ class FlutterBoost { ...@@ -155,18 +156,32 @@ class FlutterBoost {
final Route<Map<dynamic, dynamic>> route = routeBuilder != null final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page) ? routeBuilder(page)
: PageRouteBuilder<Map<dynamic, dynamic>>( : defaultRoute(page);
pageBuilder: (BuildContext context,
Animation<double> animation, FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode = true;
Animation<double> secondaryAnimation,) =>
page);
return FlutterBoost.containerManager?.onstageContainer?.push(route); return FlutterBoost.containerManager?.onstageContainer?.push(route);
} }
Route<Map<dynamic, dynamic>> defaultRoute(Widget page) {
if (Platform.isIOS) {
return CupertinoPageRoute<Map<dynamic, dynamic>> (
builder: (BuildContext context) => page
);
}
return MaterialPageRoute<Map<dynamic, dynamic>>(builder: (BuildContext context) => page);
// PageRouteBuilder<Map<dynamic, dynamic>>(
// pageBuilder: (BuildContext context,
// Animation<double> animation,
// Animation<double> secondaryAnimation,) =>
// page)
}
/** /**
* close flutter page but not close container * close flutter page but not close container if there has more than one page in contaienr
*/ */
bool closeInCurrentContainer<T extends Object>([T result]) { bool closeInCurrentContainer<T extends Object>([T result]) {
return FlutterBoost.containerManager?.onstageContainer?.pop(result); return FlutterBoost.containerManager?.onstageContainer?.pop(result);
...@@ -174,6 +189,17 @@ class FlutterBoost { ...@@ -174,6 +189,17 @@ class FlutterBoost {
Future<bool> close(String id, Future<bool> close(String id,
{Map<String, dynamic> result, Map<String, dynamic> exts}) { {Map<String, dynamic> result, Map<String, dynamic> exts}) {
//判断当前onStage的容器是不是通过openInCurrentContainer打开过界面
if (FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode ?? false) {
return Future.value(closeInCurrentContainer(result));
}
return closeInternal(id, result: result, exts: exts);
}
Future<bool> closeInternal(String id,
{Map<String, dynamic> result, Map<String, dynamic> exts}) {
assert(id != null); assert(id != null);
BoostContainerSettings settings = containerManager?.onstageSettings; BoostContainerSettings settings = containerManager?.onstageSettings;
...@@ -199,8 +225,11 @@ class FlutterBoost { ...@@ -199,8 +225,11 @@ class FlutterBoost {
properties["exts"] = exts; properties["exts"] = exts;
} }
return channel.invokeMethod<bool>('closePage', properties); return channel.invokeMethod<bool>('closePage', properties);
} }
Future<bool> closeCurrent( Future<bool> closeCurrent(
{Map<String, dynamic> result, Map<String, dynamic> exts}) { {Map<String, dynamic> result, Map<String, dynamic> exts}) {
BoostContainerSettings settings = containerManager?.onstageSettings; BoostContainerSettings settings = containerManager?.onstageSettings;
......
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