Commit 1a483401 authored by yangwu.jia's avatar yangwu.jia

modify readme

parent 50baf018
...@@ -5,32 +5,6 @@ ...@@ -5,32 +5,6 @@
<a href="https://mp.weixin.qq.com/s?__biz=MzU4MDUxOTI5NA==&mid=2247484367&idx=1&sn=fcbc485f068dae5de9f68d52607ea08f&chksm=fd54d7deca235ec86249a9e3714ec18be8b2d6dc580cae19e4e5113533a6c5b44dfa5813c4c3&scene=0&subscene=131&clicktime=1551942425&ascene=7&devicetype=android-28&version=2700033b&nettype=ctnet&abtest_cookie=BAABAAoACwASABMABAAklx4AVpkeAMSZHgDWmR4AAAA%3D&lang=zh_CN&pass_ticket=1qvHqOsbLBHv3wwAcw577EHhNjg6EKXqTfnOiFbbbaw%3D&wx_header=1">中文介绍</a> <a href="https://mp.weixin.qq.com/s?__biz=MzU4MDUxOTI5NA==&mid=2247484367&idx=1&sn=fcbc485f068dae5de9f68d52607ea08f&chksm=fd54d7deca235ec86249a9e3714ec18be8b2d6dc580cae19e4e5113533a6c5b44dfa5813c4c3&scene=0&subscene=131&clicktime=1551942425&ascene=7&devicetype=android-28&version=2700033b&nettype=ctnet&abtest_cookie=BAABAAoACwASABMABAAklx4AVpkeAMSZHgDWmR4AAAA%3D&lang=zh_CN&pass_ticket=1qvHqOsbLBHv3wwAcw577EHhNjg6EKXqTfnOiFbbbaw%3D&wx_header=1">中文介绍</a>
</p> </p>
# Latest News
Currently, version 1.9 of flutter is supported.
flutter branch:v1.9.1-hotfixes
FlutterBoost branch:feature/flutter_1.9_upgrade
FlutterBoost for androidx branch:feature/flutter_1.9_androidx_upgrade
```java
flutter_boost:
git:
url: 'https://github.com/alibaba/flutter_boost.git'
ref: 'feature/flutter_1.9_upgrade'
```
dingding group:
<img width="200" src="https://img.alicdn.com/tfs/TB1JSzVeYY1gK0jSZTEXXXDQVXa-892-1213.jpg">
# Release Note # Release Note
Please checkout the release note for the latest 0.1.54 to see changes [0.1.54 release note](https://github.com/alibaba/flutter_boost/releases) Please checkout the release note for the latest 0.1.54 to see changes [0.1.54 release note](https://github.com/alibaba/flutter_boost/releases)
...@@ -40,7 +14,7 @@ A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plug ...@@ -40,7 +14,7 @@ A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plug
<a name="bf647454"></a> <a name="bf647454"></a>
# Prerequisites # Prerequisites
You need to add Flutter to your project before moving on.The version of the flutter SDK requires v1.5.4-hotfixes, or it will compile error. You need to add Flutter to your project before moving on.The version of the flutter SDK requires v1.9.1+hotfixes, or it will compile error.
# Getting Started # Getting Started
...@@ -49,17 +23,19 @@ You need to add Flutter to your project before moving on.The version of the flut ...@@ -49,17 +23,19 @@ You need to add Flutter to your project before moving on.The version of the flut
Open you pubspec.yaml and add the following line to dependencies: Open you pubspec.yaml and add the following line to dependencies:
```java support branch
flutter_boost: ^0.1.54 ```json
flutter_boost:
git:
url: 'https://github.com/alibaba/flutter_boost.git'
ref: 'feature/flutter_1.9_upgrade'
``` ```
androidx branch
or you could rely directly on a Github project tag, for example(recommended) ```json
```java
flutter_boost: flutter_boost:
git: git:
url: 'https://github.com/alibaba/flutter_boost.git' url: 'https://github.com/alibaba/flutter_boost.git'
ref: '0.1.54' ref: 'feature/flutter_1.9_androidx_upgrade'
``` ```
...@@ -68,7 +44,9 @@ flutter_boost: ...@@ -68,7 +44,9 @@ flutter_boost:
Add init code to you App Add init code to you App
```dart ```dart
void main() => runApp(MyApp()); void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget { class MyApp extends StatefulWidget {
@override @override
...@@ -80,19 +58,31 @@ class _MyAppState extends State<MyApp> { ...@@ -80,19 +58,31 @@ class _MyAppState extends State<MyApp> {
void initState() { void initState() {
super.initState(); super.initState();
///register page widget builders,the key is pageName
FlutterBoost.singleton.registerPageBuilders({ FlutterBoost.singleton.registerPageBuilders({
'sample://firstPage': (pageName, params, _) => FirstRouteWidget(), 'first': (pageName, params, _) => FirstRouteWidget(),
'sample://secondPage': (pageName, params, _) => SecondRouteWidget(), 'second': (pageName, params, _) => SecondRouteWidget(),
'tab': (pageName, params, _) => TabRouteWidget(),
'platformView': (pageName, params, _) => PlatformRouteWidget(),
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
'flutterPage': (pageName, params, _) {
print("flutterPage params:$params");
return FlutterRouteWidget(params:params);
},
}); });
} }
@override @override
Widget build(BuildContext context) => MaterialApp( Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Boost example', title: 'Flutter Boost example',
builder: FlutterBoost.init(), ///init container manager builder: FlutterBoost.init(postPush: _onRoutePushed),
home: Container()); home: Container());
}
void _onRoutePushed(
String pageName, String uniqueId, Map params, Route route, Future _) {
}
} }
``` ```
...@@ -101,9 +91,11 @@ class _MyAppState extends State<MyApp> { ...@@ -101,9 +91,11 @@ class _MyAppState extends State<MyApp> {
Note: You need to add libc++ into "Linked Frameworks and Libraries" Note: You need to add libc++ into "Linked Frameworks and Libraries"
### objective-c:
Use FLBFlutterAppDelegate as the superclass of your AppDelegate Use FLBFlutterAppDelegate as the superclass of your AppDelegate
```objc ```objectivec
@interface AppDelegate : FLBFlutterAppDelegate <UIApplicationDelegate> @interface AppDelegate : FLBFlutterAppDelegate <UIApplicationDelegate>
@end @end
``` ```
...@@ -111,37 +103,48 @@ Use FLBFlutterAppDelegate as the superclass of your AppDelegate ...@@ -111,37 +103,48 @@ Use FLBFlutterAppDelegate as the superclass of your AppDelegate
Implement FLBPlatform protocol methods for your App. Implement FLBPlatform protocol methods for your App.
```objc
@interface PlatformRouterImp : NSObject<FLBPlatform>
```objectivec
@interface PlatformRouterImp : NSObject<FLBPlatform>
@property (nonatomic,strong) UINavigationController *navigationController; @property (nonatomic,strong) UINavigationController *navigationController;
+ (PlatformRouterImp *)sharedRouter;
@end @end
@implementation PlatformRouterImp @implementation PlatformRouterImp
- (void)openPage:(NSString *)name #pragma mark - Boost 1.5
params:(NSDictionary *)params - (void)open:(NSString *)name
animated:(BOOL)animated urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion completion:(void (^)(BOOL))completion
{ {
if([params[@"present"] boolValue]){ BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{}];
}else{
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new; FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params]; [vc setName:name params:params];
[self.navigationController pushViewController:vc animated:animated]; [self.navigationController pushViewController:vc animated:animated];
} if(completion) completion(YES);
} }
- (void)present:(NSString *)name
urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{
if(completion) completion(YES);
}];
}
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion - (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{ {
BOOL animated = [exts[@"animated"] boolValue];
animated = YES;
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController; FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){ if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}]; [vc dismissViewControllerAnimated:animated completion:^{}];
...@@ -149,7 +152,6 @@ Implement FLBPlatform protocol methods for your App. ...@@ -149,7 +152,6 @@ Implement FLBPlatform protocol methods for your App.
[self.navigationController popViewControllerAnimated:animated]; [self.navigationController popViewControllerAnimated:animated];
} }
} }
@end @end
``` ```
...@@ -165,52 +167,137 @@ Initialize FlutterBoost with FLBPlatform at the beginning of your App, such as ...@@ -165,52 +167,137 @@ Initialize FlutterBoost with FLBPlatform at the beginning of your App, such as
}]; }];
``` ```
### swift:
init
```swift
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
let router = PlatformRouterImp.init();
FlutterBoostPlugin.sharedInstance()?.startFlutter(with: router, onStart: { (engine) in
});
self.window = UIWindow.init(frame: UIScreen.main.bounds)
let viewController = ViewController.init()
let navi = UINavigationController.init(rootViewController: viewController)
self.window.rootViewController = navi
self.window.makeKeyAndVisible()
return true;//super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```
Implement FLBPlatform protocol methods for your App.
```swift
class PlatformRouterImp: NSObject, FLBPlatform {
func open(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let vc = FLBFlutterViewContainer.init();
vc.setName(url, params: urlParams);
self.navigationController().pushViewController(vc, animated: animated);
completion(true);
}
func present(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let vc = FLBFlutterViewContainer.init();
vc.setName(url, params: urlParams);
navigationController().present(vc, animated: animated) {
completion(true);
};
}
func close(_ uid: String, result: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let presentedVC = self.navigationController().presentedViewController;
let vc = presentedVC as? FLBFlutterViewContainer;
if vc?.uniqueIDString() == uid {
vc?.dismiss(animated: animated, completion: {
completion(true);
});
}else{
self.navigationController().popViewController(animated: animated);
}
}
func navigationController() -> UINavigationController {
let delegate = UIApplication.shared.delegate as! AppDelegate
let navigationController = delegate.window?.rootViewController as! UINavigationController
return navigationController;
}
}
```
## Integration with Android code. ## Integration with Android code.
Init FlutterBoost in Application.onCreate()  Init FlutterBoost in Application.onCreate() 
```java ```java
public class MyApplication extends FlutterApplication { public class MyApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
FlutterBoostPlugin.init(new IPlatform() { INativeRouter router =new INativeRouter() {
@Override @Override
public Application getApplication() { public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
return MyApplication.this; String assembleUrl=Utils.assembleUrl(url,urlParams);
PageRouter.openPageByUrl(context,assembleUrl, urlParams);
} }
};
FlutterBoost.BoostLifecycleListener lifecycleListener= new FlutterBoost.BoostLifecycleListener() {
@Override @Override
public boolean isDebug() { public void onEngineCreated() {
return true;
} }
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { public void onPluginsRegistered() {
//native open url MethodChannel mMethodChannel = new MethodChannel( FlutterBoost.instance().engineProvider().getDartExecutor(), "methodChannel");
Log.e("MyApplication","MethodChannel create");
TextPlatformViewPlugin.register(FlutterBoost.instance().getPluginRegistry().registrarFor("TextPlatformViewPlugin"));
} }
@Override @Override
public IFlutterEngineProvider engineProvider() { public void onEngineDestroy() {
return new BoostEngineProvider(){
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
} }
}; };
} Platform platform= new FlutterBoost
.ConfigBuilder(this,router)
.isDebug(true)
.whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(lifecycleListener)
.build();
FlutterBoost.instance().init(platform);
@Override
public int whenEngineStart() {
return ANY_ACTIVITY_CREATED;
}
});
} }
}
``` ```
...@@ -250,40 +337,52 @@ However, in this way, you cannot get the page data result after the page finishe ...@@ -250,40 +337,52 @@ However, in this way, you cannot get the page data result after the page finishe
Android Android
```java ```java
public class FlutterPageActivity extends BoostFlutterActivity { public class PageRouter {
public final static Map<String, String> pageName = new HashMap<String, String>() {{
@Override
public String getContainerUrl() {
//specify the page name register in FlutterBoost
return "sample://firstPage";
}
@Override put("first", "first");
public Map getContainerUrlParams() { put("second", "second");
//params of the page put("tab", "tab");
Map<String,String> params = new HashMap<>();
params.put("key","value");
return params;
}
}
```
or put("sample://flutterPage", "flutterPage");
}};
```java public static final String NATIVE_PAGE_URL = "sample://nativePage";
public static final String FLUTTER_PAGE_URL = "sample://flutterPage";
public static final String FLUTTER_FRAGMENT_PAGE_URL = "sample://flutterFragmentPage";
public class FlutterFragment extends BoostFlutterFragment { public static boolean openPageByUrl(Context context, String url, Map params) {
@Override return openPageByUrl(context, url, params, 0);
public String getContainerUrl() {
return "flutterFragment";
} }
@Override public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) {
public Map getContainerUrlParams() {
Map<String,String> params = new HashMap<>(); String path = url.split("\\?")[0];
params.put("tag",getArguments().getString("tag"));
return params; Log.i("openPageByUrl",path);
try {
if (pageName.containsKey(path)) {
Intent intent = BoostFlutterActivity.withNewEngine().url(pageName.get(path)).params(params)
.backgroundMode(BoostFlutterActivity.BackgroundMode.opaque).build(context);
context.startActivity(intent);
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
return true;
} else if (url.startsWith(NATIVE_PAGE_URL)) {
context.startActivity(new Intent(context, NativePageActivity.class));
return true;
} else {
return false;
}
} catch (Throwable t) {
return false;
}
return false;
} }
} }
``` ```
...@@ -316,6 +415,12 @@ Please see the example for details. ...@@ -316,6 +415,12 @@ Please see the example for details.
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
# Problem feedback group( dingding group)
<img width="200" src="https://img.alicdn.com/tfs/TB1JSzVeYY1gK0jSZTEXXXDQVXa-892-1213.jpg">
## 关于我们 ## 关于我们
阿里巴巴-闲鱼技术是国内最早也是最大规模线上运行Flutter的团队。 阿里巴巴-闲鱼技术是国内最早也是最大规模线上运行Flutter的团队。
......
...@@ -2,31 +2,10 @@ ...@@ -2,31 +2,10 @@
<img src="flutter_boost.png"> <img src="flutter_boost.png">
</p> </p>
# 项目最新动态
目前已经支持flutter 1.9版本。
对应的flutter 版本是:v1.9.1-hotfixes
flutter boost分支是:feature/flutter_1.9_upgrade
flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade
代码引入方式:
```java
flutter_boost:
git:
url: 'https://github.com/alibaba/flutter_boost.git'
ref: 'feature/flutter_1.9_upgrade'
```
# Release Note # Release Note
请查看最新版本0.1.50的release note 确认变更,[0.1.50 release note](https://github.com/alibaba/flutter_boost/releases) 请查看最新版本0.1.54的release note 确认变更,[0.1.54 release note](https://github.com/alibaba/flutter_boost/releases)
# FlutterBoost # FlutterBoost
...@@ -34,7 +13,8 @@ flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade ...@@ -34,7 +13,8 @@ flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade
# 前置条件 # 前置条件
在继续之前,您需要将Flutter集成到你现有的项目中。flutter sdk 的版本需要 v1.5.4-hotfixes,否则会编译失败.
在继续之前,您需要将Flutter集成到你现有的项目中。flutter sdk 的版本需要 v1.9.1-hotfixes,否则会编译失败.
# 安装 # 安装
...@@ -42,25 +22,29 @@ flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade ...@@ -42,25 +22,29 @@ flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade
打开pubspec.yaml并将以下行添加到依赖项: 打开pubspec.yaml并将以下行添加到依赖项:
support分支
```json ```json
flutter_boost: ^0.1.54 flutter_boost:
git:
url: 'https://github.com/alibaba/flutter_boost.git'
ref: 'feature/flutter_1.9_upgrade'
``` ```
或者可以直接依赖github的项目的版本,Tag,pub发布会有延迟,推荐直接依赖Github项目 androidx分支
```json
```java
flutter_boost: flutter_boost:
git: git:
url: 'https://github.com/alibaba/flutter_boost.git' url: 'https://github.com/alibaba/flutter_boost.git'
ref: '0.1.54' ref: 'feature/flutter_1.9_androidx_upgrade'
``` ```
## Dart代码的集成 ## Dart代码的集成
将init代码添加到App App 将init代码添加到App App
```dart ```dart
void main() => runApp(MyApp()); void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget { class MyApp extends StatefulWidget {
@override @override
...@@ -72,19 +56,31 @@ class _MyAppState extends State<MyApp> { ...@@ -72,19 +56,31 @@ class _MyAppState extends State<MyApp> {
void initState() { void initState() {
super.initState(); super.initState();
///register page widget builders,the key is pageName
FlutterBoost.singleton.registerPageBuilders({ FlutterBoost.singleton.registerPageBuilders({
'sample://firstPage': (pageName, params, _) => FirstRouteWidget(), 'first': (pageName, params, _) => FirstRouteWidget(),
'sample://secondPage': (pageName, params, _) => SecondRouteWidget(), 'second': (pageName, params, _) => SecondRouteWidget(),
'tab': (pageName, params, _) => TabRouteWidget(),
'platformView': (pageName, params, _) => PlatformRouteWidget(),
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
'flutterPage': (pageName, params, _) {
print("flutterPage params:$params");
return FlutterRouteWidget(params:params);
},
}); });
} }
@override @override
Widget build(BuildContext context) => MaterialApp( Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Boost example', title: 'Flutter Boost example',
builder: FlutterBoost.init(), ///init container manager builder: FlutterBoost.init(postPush: _onRoutePushed),
home: Container()); home: Container());
}
void _onRoutePushed(
String pageName, String uniqueId, Map params, Route route, Future _) {
}
} }
``` ```
...@@ -92,6 +88,8 @@ class _MyAppState extends State<MyApp> { ...@@ -92,6 +88,8 @@ class _MyAppState extends State<MyApp> {
注意:需要将libc++ 加入 "Linked Frameworks and Libraries" 中。 注意:需要将libc++ 加入 "Linked Frameworks and Libraries" 中。
### objective-c:
使用FLBFlutterAppDelegate作为AppDelegate的超类 使用FLBFlutterAppDelegate作为AppDelegate的超类
```objectivec ```objectivec
...@@ -104,35 +102,45 @@ class _MyAppState extends State<MyApp> { ...@@ -104,35 +102,45 @@ class _MyAppState extends State<MyApp> {
```objectivec ```objectivec
@interface PlatformRouterImp : NSObject<FLBPlatform> @interface PlatformRouterImp : NSObject<FLBPlatform>
@property (nonatomic,strong) UINavigationController *navigationController; @property (nonatomic,strong) UINavigationController *navigationController;
+ (PlatformRouterImp *)sharedRouter;
@end @end
@implementation PlatformRouterImp @implementation PlatformRouterImp
- (void)openPage:(NSString *)name #pragma mark - Boost 1.5
params:(NSDictionary *)params - (void)open:(NSString *)name
animated:(BOOL)animated urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion completion:(void (^)(BOOL))completion
{ {
if([params[@"present"] boolValue]){ BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{}];
}else{
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new; FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params]; [vc setName:name params:params];
[self.navigationController pushViewController:vc animated:animated]; [self.navigationController pushViewController:vc animated:animated];
} if(completion) completion(YES);
} }
- (void)present:(NSString *)name
urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{
if(completion) completion(YES);
}];
}
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion - (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{ {
BOOL animated = [exts[@"animated"] boolValue];
animated = YES;
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController; FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){ if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}]; [vc dismissViewControllerAnimated:animated completion:^{}];
...@@ -140,66 +148,150 @@ class _MyAppState extends State<MyApp> { ...@@ -140,66 +148,150 @@ class _MyAppState extends State<MyApp> {
[self.navigationController popViewControllerAnimated:animated]; [self.navigationController popViewControllerAnimated:animated];
} }
} }
@end @end
``` ```
在应用程序开头使用FLBPlatform初始化FlutterBoost。 在应用程序开头使用FLBPlatform初始化FlutterBoost。
```objc ```objc
PlatformRouterImp *router = [PlatformRouterImp new]; PlatformRouterImp *router = [PlatformRouterImp new];
[FlutterBoostPlugin.sharedInstance startFlutterWithPlatformrouter [FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router
onStart^FlutterEngine *engine{ onStart:^(FlutterEngine *engine) {
}]; }];
``` ```
### swift:
初始化
```swift
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
let router = PlatformRouterImp.init();
FlutterBoostPlugin.sharedInstance()?.startFlutter(with: router, onStart: { (engine) in
});
self.window = UIWindow.init(frame: UIScreen.main.bounds)
let viewController = ViewController.init()
let navi = UINavigationController.init(rootViewController: viewController)
self.window.rootViewController = navi
self.window.makeKeyAndVisible()
return true;//super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```
为您的应用程序实现FLBPlatform协议方法。
```swift
class PlatformRouterImp: NSObject, FLBPlatform {
func open(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let vc = FLBFlutterViewContainer.init();
vc.setName(url, params: urlParams);
self.navigationController().pushViewController(vc, animated: animated);
completion(true);
}
func present(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let vc = FLBFlutterViewContainer.init();
vc.setName(url, params: urlParams);
navigationController().present(vc, animated: animated) {
completion(true);
};
}
func close(_ uid: String, result: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
var animated = false;
if exts["animated"] != nil{
animated = exts["animated"] as! Bool;
}
let presentedVC = self.navigationController().presentedViewController;
let vc = presentedVC as? FLBFlutterViewContainer;
if vc?.uniqueIDString() == uid {
vc?.dismiss(animated: animated, completion: {
completion(true);
});
}else{
self.navigationController().popViewController(animated: animated);
}
}
func navigationController() -> UINavigationController {
let delegate = UIApplication.shared.delegate as! AppDelegate
let navigationController = delegate.window?.rootViewController as! UINavigationController
return navigationController;
}
}
```
## Android代码集成。 ## Android代码集成。
在Application.onCreate()中初始化FlutterBoost 在Application.onCreate()中初始化FlutterBoost
```java ```java
public class MyApplication extends FlutterApplication { public class MyApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
FlutterBoostPlugin.init(new IPlatform() { INativeRouter router =new INativeRouter() {
@Override @Override
public Application getApplication() { public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
return MyApplication.this; String assembleUrl=Utils.assembleUrl(url,urlParams);
PageRouter.openPageByUrl(context,assembleUrl, urlParams);
} }
};
FlutterBoost.BoostLifecycleListener lifecycleListener= new FlutterBoost.BoostLifecycleListener() {
@Override @Override
public boolean isDebug() { public void onEngineCreated() {
return true;
} }
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { public void onPluginsRegistered() {
PageRouter.openPageByUrl(context,url,urlParams,requestCode); MethodChannel mMethodChannel = new MethodChannel( FlutterBoost.instance().engineProvider().getDartExecutor(), "methodChannel");
Log.e("MyApplication","MethodChannel create");
TextPlatformViewPlugin.register(FlutterBoost.instance().getPluginRegistry().registrarFor("TextPlatformViewPlugin"));
} }
@Override @Override
public IFlutterEngineProvider engineProvider() { public void onEngineDestroy() {
return new BoostEngineProvider(){
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
} }
}; };
} Platform platform= new FlutterBoost
.ConfigBuilder(this,router)
.isDebug(true)
.whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(lifecycleListener)
.build();
FlutterBoost.instance().init(platform);
@Override
public int whenEngineStart() {
return ANY_ACTIVITY_CREATED;
}
});
} }
}
``` ```
# 基本用法 # 基本用法
...@@ -236,40 +328,52 @@ public class MyApplication extends FlutterApplication { ...@@ -236,40 +328,52 @@ public class MyApplication extends FlutterApplication {
Android Android
```java ```java
public class FlutterPageActivity extends BoostFlutterActivity { public class PageRouter {
public final static Map<String, String> pageName = new HashMap<String, String>() {{
@Override
public String getContainerUrl() {
//specify the page name register in FlutterBoost
return "sample://firstPage";
}
@Override put("first", "first");
public Map getContainerUrlParams() { put("second", "second");
//params of the page put("tab", "tab");
Map<String,String> params = new HashMap<>();
params.put("key","value");
return params;
}
}
```
或者用Fragment put("sample://flutterPage", "flutterPage");
}};
```java public static final String NATIVE_PAGE_URL = "sample://nativePage";
public class FlutterFragment extends BoostFlutterFragment { public static final String FLUTTER_PAGE_URL = "sample://flutterPage";
public static final String FLUTTER_FRAGMENT_PAGE_URL = "sample://flutterFragmentPage";
@Override public static boolean openPageByUrl(Context context, String url, Map params) {
public String getContainerUrl() { return openPageByUrl(context, url, params, 0);
return "sample://firstPage";
} }
@Override public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) {
public Map getContainerUrlParams() {
Map<String,String> params = new HashMap<>(); String path = url.split("\\?")[0];
params.put("key","value");
return params; Log.i("openPageByUrl",path);
try {
if (pageName.containsKey(path)) {
Intent intent = BoostFlutterActivity.withNewEngine().url(pageName.get(path)).params(params)
.backgroundMode(BoostFlutterActivity.BackgroundMode.opaque).build(context);
context.startActivity(intent);
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
return true;
} else if (url.startsWith(NATIVE_PAGE_URL)) {
context.startActivity(new Intent(context, NativePageActivity.class));
return true;
} else {
return false;
}
} catch (Throwable t) {
return false;
}
return false;
} }
} }
``` ```
......
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