Commit 5740f8d9 authored by ColdPaleLight's avatar ColdPaleLight

support close page without close container

parent e26ead11
......@@ -135,6 +135,8 @@ class BoostContainerState extends NavigatorState {
final List<Route<dynamic>> routerHistory = <Route<dynamic>>[];
bool multipleRouteMode = false;
ContainerNavigatorObserver findContainerNavigatorObserver(
Navigator navigator) {
for (NavigatorObserver observer in navigator.observers) {
......@@ -202,9 +204,9 @@ class BoostContainerState extends NavigatorState {
} else {
if (T is Map<String, dynamic>) {
FlutterBoost.singleton
.close(uniqueId, result: result as Map<String, dynamic>);
.closeInternal(uniqueId, result: result as Map<String, dynamic>);
} else {
FlutterBoost.singleton.close(uniqueId);
FlutterBoost.singleton.closeInternal(uniqueId,);
}
}
return true;
......
......@@ -24,6 +24,7 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'container/boost_container.dart';
import 'container/container_coordinator.dart';
......@@ -144,9 +145,9 @@ class FlutterBoost {
Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) {
if(!ContainerCoordinator.singleton.isFlutterPageUrl(url)){
return open(url, urlParams: urlParams, exts: exts);
}
// if(!ContainerCoordinator.singleton.isFlutterPageUrl(url)){
// return open(url, urlParams: urlParams, exts: exts);
// }
String uniqueId='${url}_${DateTime.now().millisecondsSinceEpoch}';
......@@ -155,18 +156,32 @@ class FlutterBoost {
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: PageRouteBuilder<Map<dynamic, dynamic>>(
pageBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,) =>
page);
: defaultRoute(page);
FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode = true;
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]) {
return FlutterBoost.containerManager?.onstageContainer?.pop(result);
......@@ -174,6 +189,17 @@ class FlutterBoost {
Future<bool> close(String id,
{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);
BoostContainerSettings settings = containerManager?.onstageSettings;
......@@ -199,8 +225,11 @@ 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;
......
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