Commit 6db19519 authored by ColdPaleLight's avatar ColdPaleLight

flutter page to flutter page without native container

parent 253f2d67
...@@ -16,6 +16,8 @@ public class PageRouter { ...@@ -16,6 +16,8 @@ public class PageRouter {
put("first", "first"); put("first", "first");
put("second", "second"); put("second", "second");
put("tab", "tab"); put("tab", "tab");
put("f2f_first", "f2f_first");
put("f2f_second", "f2f_second");
put("sample://flutterPage", "flutterPage"); put("sample://flutterPage", "flutterPage");
}}; }};
......
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
class F2FFirstPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new F2FFirstPageState();
}
}
class F2FFirstPageState extends State<F2FFirstPage>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child:
Column(
mainAxisAlignment: MainAxisAlignment.center,
children:
<Widget>[
RaisedButton(
child: Text('Open second with native container'),
onPressed: () {
FlutterBoost.singleton.open("f2f_second");
},
),
RaisedButton(
child: Text('Open second without native container'),
onPressed: () {
FlutterBoostAPI.singleton.open("f2f_second",noNeedNativeContainer: true);
},
),
],
),
),
);
}
}
class F2FSecondPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new F2FSecondPageState();
}
}
class F2FSecondPageState extends State<F2FSecondPage>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Route'),
),
body: Center(
child:
Column(
mainAxisAlignment: MainAxisAlignment.center,
children:
<Widget>[
Text('Hello')
],
),
),
);
}
}
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'simple_page_widgets.dart'; import 'simple_page_widgets.dart';
import 'flutter_to_flutter_sample.dart';
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
...@@ -31,8 +32,17 @@ class _MyAppState extends State<MyApp> { ...@@ -31,8 +32,17 @@ class _MyAppState extends State<MyApp> {
return FlutterRouteWidget(params:params); return FlutterRouteWidget(params:params);
}, },
'f2f_first': (pageName, params, _) => F2FFirstPage(),
'f2f_second': (pageName, params, _) => F2FSecondPage(),
}); });
FlutterBoost.singleton.addBoostNavigatorObserver(TestBoostNavigatorObserver()); FlutterBoost.singleton.addBoostNavigatorObserver(TestBoostNavigatorObserver());
FlutterBoostAPI.singleton.routeSettingsBuilder = (String url,
{Map<String, dynamic> urlParams, Map<String, dynamic> exts}) => BoostRouteSettings(
uniqueId: '${url}_${DateTime.now().millisecondsSinceEpoch}',
name: url,
params: urlParams,
);
} }
@override @override
......
...@@ -105,6 +105,16 @@ class _FirstRouteWidgetState extends State<FirstRouteWidget>{ ...@@ -105,6 +105,16 @@ class _FirstRouteWidgetState extends State<FirstRouteWidget>{
}); });
}, },
), ),
RaisedButton(
child: Text('Flutter to Flutter with Animation'),
onPressed: () {
FlutterBoost.singleton.open("f2f_first").then((Map<dynamic,dynamic> value) {
print(
"call me when page is finished. did recieve second route result $value");
});
}
)
], ],
), ),
), ),
......
...@@ -40,6 +40,7 @@ class ContainerCoordinator { ...@@ -40,6 +40,7 @@ class ContainerCoordinator {
final Map<String, PageBuilder> _pageBuilders = <String, PageBuilder>{}; final Map<String, PageBuilder> _pageBuilders = <String, PageBuilder>{};
PageBuilder _defaultPageBuilder; PageBuilder _defaultPageBuilder;
ContainerCoordinator(BoostChannel channel) { ContainerCoordinator(BoostChannel channel) {
assert(_instance == null); assert(_instance == null);
...@@ -60,6 +61,21 @@ class ContainerCoordinator { ...@@ -60,6 +61,21 @@ class ContainerCoordinator {
name: name, name: name,
params: params, params: params,
builder: (BuildContext ctx) { builder: (BuildContext ctx) {
page = createPage(name, params, pageId);
assert(page != null);
Logger.log('build widget:$page for page:$name($pageId)');
return page;
});
return routeSettings;
}
Widget createPage(String name, Map params, String pageId) {
Widget page;
//Try to build a page using keyed builder. //Try to build a page using keyed builder.
if (_pageBuilders[name] != null) { if (_pageBuilders[name] != null) {
page = _pageBuilders[name](name, params, pageId); page = _pageBuilders[name](name, params, pageId);
...@@ -70,13 +86,7 @@ class ContainerCoordinator { ...@@ -70,13 +86,7 @@ class ContainerCoordinator {
page = _defaultPageBuilder(name, params, pageId); page = _defaultPageBuilder(name, params, pageId);
} }
assert(page != null);
Logger.log('build widget:$page for page:$name($pageId)');
return page; return page;
});
return routeSettings;
} }
//Register a default page builder. //Register a default page builder.
......
...@@ -26,6 +26,7 @@ import 'dart:io'; ...@@ -26,6 +26,7 @@ import 'dart:io';
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_manager.dart'; import 'container/container_manager.dart';
import 'channel/boost_channel.dart'; import 'channel/boost_channel.dart';
...@@ -34,6 +35,7 @@ import 'observers_holders.dart'; ...@@ -34,6 +35,7 @@ import 'observers_holders.dart';
export 'container/boost_container.dart'; export 'container/boost_container.dart';
export 'container/container_manager.dart'; export 'container/container_manager.dart';
export 'flutter_boost_api.dart';
typedef Widget PageBuilder(String pageName, Map params, String uniqueId); typedef Widget PageBuilder(String pageName, Map params, String uniqueId);
...@@ -121,11 +123,16 @@ class FlutterBoost { ...@@ -121,11 +123,16 @@ class FlutterBoost {
} }
Future<Map<dynamic, dynamic>> open(String url, Future<Map<dynamic, dynamic>> open(String url,
{Map<String, dynamic> urlParams, Map<String, dynamic> exts}) { {Map<String, dynamic> urlParams,
Map<String, dynamic> exts}) {
Map<String, dynamic> properties = new Map<String, dynamic>(); Map<String, dynamic> properties = new Map<String, dynamic>();
properties["url"] = url; properties["url"] = url;
properties["urlParams"] = urlParams; properties["urlParams"] = urlParams;
properties["exts"] = exts; properties["exts"] = exts;
//TODO 判断是不是需要跳Flutter,有没有前置拦截逻辑,如果都没有,就找到Navigator去把页面推进去
return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties); return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties);
} }
......
import 'package:flutter/widgets.dart';
import 'container/container_coordinator.dart';
import 'flutter_boost.dart';
import 'flutter_boost.dart';
import 'flutter_boost.dart';
typedef Route FlutterBoostRouteBuilder(Widget widget);
class BoostRouteSettings {
final String uniqueId;
final String name;
final Map params;
const BoostRouteSettings({this.uniqueId, this.name, this.params});
}
typedef BoostRouteSettings BoostRouteSettingsBuilder(String url,
{Map<String, dynamic> urlParams, Map<String, dynamic> exts});
class FlutterBoostAPI {
static final FlutterBoostAPI _instance = FlutterBoostAPI();
static FlutterBoostAPI get singleton => _instance;
BoostRouteSettingsBuilder routeSettingsBuilder;
Future<Map<dynamic, dynamic>> open(String url,
{Map<String, dynamic> urlParams,
Map<String, dynamic> exts,
bool noNeedNativeContainer,
FlutterBoostRouteBuilder routeBuilder}) {
if (noNeedNativeContainer) {
final BoostRouteSettings routeSettings =
routeSettingsBuilder(url, urlParams: urlParams, exts: exts);
final Widget page = ContainerCoordinator.singleton.createPage(
routeSettings.name, routeSettings.params, routeSettings.uniqueId);
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: PageRouteBuilder<Map<dynamic, dynamic>>(
pageBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) =>
page);
if (route != null) {
return FlutterBoost.containerManager?.onstageContainer?.push(route);
}
return Future<Map<dynamic, dynamic>>.value(<dynamic, dynamic>{});
}
return FlutterBoost.singleton.open(url, urlParams: urlParams, exts: exts);
}
bool close<T extends Object>([T result]) {
return FlutterBoost.containerManager?.onstageContainer?.pop(result);
}
}
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