Commit bf030eb4 authored by justin's avatar justin

增加willPush 方法

parent c5849a24
......@@ -37,6 +37,12 @@ class _MyAppState extends State<MyApp> {
'f2f_second': (pageName, params, _) => F2FSecondPage(),
});
FlutterBoost.singleton.addBoostNavigatorObserver(TestBoostNavigatorObserver());
FlutterBoost.singleton.addContainerObserver((
ContainerOperation operation, BoostContainerSettings settings){
operation;
settings;
});
FlutterBoostAPI.singleton.routeSettingsBuilder = (String url,
{Map<String, dynamic> urlParams, Map<String, dynamic> exts}) => BoostRouteSettings(
uniqueId: '${url}_${DateTime.now().millisecondsSinceEpoch}',
......@@ -59,9 +65,13 @@ class _MyAppState extends State<MyApp> {
String pageName, String uniqueId, Map params, Route route, Future _) {
}
}
class TestBoostNavigatorObserver extends NavigatorObserver{
class TestBoostNavigatorObserver extends ContainerNavigatorObserver{
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
route.settings.name!="/";
//1. 底下
//新页面已经push完成
print("flutterboost#didPush");
}
......@@ -76,5 +86,10 @@ class TestBoostNavigatorObserver extends NavigatorObserver{
void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) {
print("flutterboost#didReplace");
}
void willPush(Route<dynamic> route, Route<dynamic> previousRoute) {
print("flutterboost#willPush");
}
}
......@@ -227,6 +227,10 @@ class BoostContainerState extends NavigatorState {
.prePushRoute(name, uniqueId, params, route);
}
if (multipleRouteMode) {
ContainerNavigatorObserver.bindContainerManager().willPush(route, routerHistory.last);
}
Future<T> future = super.push<T>(newRoute ?? route);
routerHistory.add(route);
......@@ -289,6 +293,14 @@ class ContainerNavigatorObserver extends NavigatorObserver {
boostObservers.remove(observer);
}
void willPush(Route<dynamic> route, Route<dynamic> previousRoute) {
for (NavigatorObserver observer in boostObservers) {
if(observer is ContainerNavigatorObserver){
ContainerNavigatorObserver containerNavigatorObserver = observer as ContainerNavigatorObserver;
containerNavigatorObserver.willPush(route, previousRoute);
}
}
}
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
for (NavigatorObserver observer in boostObservers) {
......
......@@ -77,7 +77,8 @@ class FlutterBoost {
pageInfo["name"], pageInfo["params"], pageInfo["uniqueId"]);
}
});
});
}
);
}
static TransitionBuilder init({TransitionBuilder builder,
......@@ -167,7 +168,7 @@ class FlutterBoost {
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: defaultRoute(page);
: defaultRoute(page,routeSettings);
FlutterBoost.containerManager?.onstageContainer?.multipleRouteMode = true;
......@@ -176,14 +177,17 @@ class FlutterBoost {
}
Route<Map<dynamic, dynamic>> defaultRoute(Widget page) {
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>> (
settings: routeSettings,
builder: (BuildContext context) => page
);
}
return PageRouteBuilder(
transitionDuration: Duration(milliseconds: 300),
settings:routeSettings ,
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var offsetAnimation = Tween<Offset>(
......
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