Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flutter_boost_1.22.4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢冠章
flutter_boost_1.22.4
Commits
1a483401
Commit
1a483401
authored
Nov 13, 2019
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify readme
parent
50baf018
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
462 additions
and
253 deletions
+462
-253
README.md
README.md
+234
-129
README_CN.md
README_CN.md
+228
-124
No files found.
README.md
View file @
1a483401
...
@@ -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,31 +44,45 @@ flutter_boost:
...
@@ -68,31 +44,45 @@ 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
_MyAppState
createState
()
=>
_MyAppState
();
_MyAppState
createState
()
=>
_MyAppState
();
}
}
class
_MyAppState
extends
State
<
MyApp
>
{
class
_MyAppState
extends
State
<
MyApp
>
{
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
///register page widget builders,the key is pageName
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
({
'first'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'sample://firstPage'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'second'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'sample://secondPage'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'tab'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
});
'platformView'
:
(
pageName
,
params
,
_
)
=>
PlatformRouteWidget
(),
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
}
'flutterPage'
:
(
pageName
,
params
,
_
)
{
print
(
"flutterPage params:
$params
"
);
@override
Widget
build
(
BuildContext
context
)
=>
MaterialApp
(
return
FlutterRouteWidget
(
params:
params
);
title:
'Flutter Boost example'
,
},
builder:
FlutterBoost
.
init
(),
///init container manager
});
home:
Container
());
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Flutter Boost example'
,
builder:
FlutterBoost
.
init
(
postPush:
_onRoutePushed
),
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
```
obj
ective
c
@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
completion
:(
void
(
^
)(
BOOL
))
completion
exts
:(
NSDictionary
*
)
exts
completion
:(
void
(
^
)(
BOOL
))
completion
{
{
if
([
params
[
@"present"
]
boolValue
]){
BOOL
animated
=
[
exts
[
@"animated"
]
boolValue
];
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
[
vc
setName
:
name
params
:
params
];
[
vc
setName
:
name
params
:
params
];
[
self
.
navigationController
presentViewController
:
vc
animated
:
animated
completion
:^
{}];
[
self
.
navigationController
pushViewController
:
vc
animated
:
animated
];
}
else
{
if
(
completion
)
completion
(
YES
);
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
[
vc
setName
:
name
params
:
params
];
[
self
.
navigationController
pushViewController
:
vc
animated
:
animated
];
}
}
}
-
(
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
```
```
...
@@ -158,59 +160,144 @@ Implement FLBPlatform protocol methods for your App.
...
@@ -158,59 +160,144 @@ Implement FLBPlatform protocol methods for your App.
Initialize FlutterBoost with FLBPlatform at the beginning of your App, such as AppDelegate.
Initialize FlutterBoost with FLBPlatform at the beginning of your App, such as AppDelegate.
```
objc
```
objc
PlatformRouterImp
*
router
=
[
PlatformRouterImp
new
];
PlatformRouterImp
*
router
=
[
PlatformRouterImp
new
];
[
FlutterBoostPlugin
.
sharedInstance
startFlutterWithPlatform
:
router
[
FlutterBoostPlugin
.
sharedInstance
startFlutterWithPlatform
:
router
onStart:
^
(
FlutterEngine
*
engine
)
{
onStart:
^
(
FlutterEngine
*
engine
)
{
}];
}];
```
```
### 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
public
Application
getApplication
()
{
return
MyApplication
.
this
;
}
@Override
@Override
public
boolean
isDebug
()
{
public
void
openContainer
(
Context
context
,
String
url
,
Map
<
String
,
Object
>
urlParams
,
int
requestCode
,
Map
<
String
,
Object
>
exts
)
{
return
true
;
String
assembleUrl
=
Utils
.
assembleUrl
(
url
,
urlParams
);
PageRouter
.
openPageByUrl
(
context
,
assembleUrl
,
urlParams
);
}
}
};
FlutterBoost
.
BoostLifecycleListener
lifecycleListener
=
new
FlutterBoost
.
BoostLifecycleListener
()
{
@Override
@Override
public
void
o
penContainer
(
Context
context
,
String
url
,
Map
<
String
,
Object
>
urlParams
,
int
requestCode
,
Map
<
String
,
Object
>
exts
)
{
public
void
o
nEngineCreated
(
)
{
//native open url
}
}
@Override
@Override
public
IFlutterEngineProvider
engineProvider
()
{
public
void
onPluginsRegistered
()
{
return
new
BoostEngineProvider
(){
MethodChannel
mMethodChannel
=
new
MethodChannel
(
FlutterBoost
.
instance
().
engineProvider
().
getDartExecutor
(),
"methodChannel"
);
@Override
Log
.
e
(
"MyApplication"
,
"MethodChannel create"
);
public
BoostFlutterEngine
createEngine
(
Context
context
)
{
TextPlatformViewPlugin
.
register
(
FlutterBoost
.
instance
().
getPluginRegistry
().
registrarFor
(
"TextPlatformViewPlugin"
));
return
new
BoostFlutterEngine
(
context
,
new
DartExecutor
.
DartEntrypoint
(
context
.
getResources
().
getAssets
(),
FlutterMain
.
findAppBundlePath
(
context
),
"main"
),
"/"
);
}
};
}
}
@Override
@Override
public
int
whenEngineStart
()
{
public
void
onEngineDestroy
()
{
return
ANY_ACTIVITY_CREATED
;
}
}
};
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
);
});
}
}
}
```
```
...
@@ -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的团队。
...
...
README_CN.md
View file @
1a483401
...
@@ -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.5
0的release note 确认变更,
[
0.1.50
release note
](
https://github.com/alibaba/flutter_boost/releases
)
。
请查看最新版本0.1.5
4的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,49 +22,65 @@ flutter boost androidx 分支是:feature/flutter_1.9_androidx_upgrade
...
@@ -42,49 +22,65 @@ 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
_MyAppState
createState
()
=>
_MyAppState
();
_MyAppState
createState
()
=>
_MyAppState
();
}
}
class
_MyAppState
extends
State
<
MyApp
>
{
class
_MyAppState
extends
State
<
MyApp
>
{
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
///register page widget builders,the key is pageName
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
({
'first'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'sample://firstPage'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'second'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'sample://secondPage'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'tab'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
});
'platformView'
:
(
pageName
,
params
,
_
)
=>
PlatformRouteWidget
(),
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
}
'flutterPage'
:
(
pageName
,
params
,
_
)
{
print
(
"flutterPage params:
$params
"
);
@override
Widget
build
(
BuildContext
context
)
=>
MaterialApp
(
return
FlutterRouteWidget
(
params:
params
);
title:
'Flutter Boost example'
,
},
builder:
FlutterBoost
.
init
(),
///init container manager
});
home:
Container
());
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Flutter Boost example'
,
builder:
FlutterBoost
.
init
(
postPush:
_onRoutePushed
),
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
completion
:(
void
(
^
)(
BOOL
))
completion
exts
:(
NSDictionary
*
)
exts
completion
:(
void
(
^
)(
BOOL
))
completion
{
{
if
([
params
[
@"present"
]
boolValue
]){
BOOL
animated
=
[
exts
[
@"animated"
]
boolValue
];
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
[
vc
setName
:
name
params
:
params
];
[
vc
setName
:
name
params
:
params
];
[
self
.
navigationController
presentViewController
:
vc
animated
:
animated
completion
:^
{}];
[
self
.
navigationController
pushViewController
:
vc
animated
:
animated
];
}
else
{
if
(
completion
)
completion
(
YES
);
FLBFlutterViewContainer
*
vc
=
FLBFlutterViewContainer
.
new
;
[
vc
setName
:
name
params
:
params
];
[
self
.
navigationController
pushViewController
:
vc
animated
:
animated
];
}
}
}
-
(
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
startFlutterWithPlatform
:
router
[
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
);
}
}
@Override
};
public
boolean
isDebug
()
{
return
true
;
}
FlutterBoost
.
BoostLifecycleListener
lifecycleListener
=
new
FlutterBoost
.
BoostLifecycleListener
()
{
@Override
@Override
public
void
o
penContainer
(
Context
context
,
String
url
,
Map
<
String
,
Object
>
urlParams
,
int
requestCode
,
Map
<
String
,
Object
>
exts
)
{
public
void
o
nEngineCreated
(
)
{
PageRouter
.
openPageByUrl
(
context
,
url
,
urlParams
,
requestCode
);
}
}
@Override
@Override
public
IFlutterEngineProvider
engineProvider
()
{
public
void
onPluginsRegistered
()
{
return
new
BoostEngineProvider
(){
MethodChannel
mMethodChannel
=
new
MethodChannel
(
FlutterBoost
.
instance
().
engineProvider
().
getDartExecutor
(),
"methodChannel"
);
@Override
Log
.
e
(
"MyApplication"
,
"MethodChannel create"
);
public
BoostFlutterEngine
createEngine
(
Context
context
)
{
TextPlatformViewPlugin
.
register
(
FlutterBoost
.
instance
().
getPluginRegistry
().
registrarFor
(
"TextPlatformViewPlugin"
));
return
new
BoostFlutterEngine
(
context
,
new
DartExecutor
.
DartEntrypoint
(
context
.
getResources
().
getAssets
(),
FlutterMain
.
findAppBundlePath
(
context
),
"main"
),
"/"
);
}
};
}
}
@Override
@Override
public
int
whenEngineStart
()
{
public
void
onEngineDestroy
()
{
return
ANY_ACTIVITY_CREATED
;
}
}
});
};
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
);
}
}
}
```
```
# 基本用法
# 基本用法
...
@@ -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
;
}
}
}
}
```
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment