Skip to content

Commit 77ef993

Browse files
init
0 parents  commit 77ef993

File tree

199 files changed

+11981
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+11981
-0
lines changed

Diff for: .gitignore

Whitespace-only changes.

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* TODO: Describe initial release.

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Alibaba Group
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Diff for: README.md

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
<p align="center">
2+
<img src="flutter_boost.png">
3+
<b></b><br>
4+
<a href="README_CN.md">中文文档</a>
5+
<br><br>
6+
</p>
7+
8+
# FlutterBoost
9+
A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts.The philosophy of FlutterBoost is to use Flutter as easy as using a WebView. Managing Native pages and Flutter pages at the same time is non-trivial in an existing App. FlutterBoost takes care of page resolution for you. The only thing you need to care about is the name of the page(usually could be an URL). 
10+
<a name="bf647454"></a>
11+
12+
# Prerequisites
13+
You need to add Flutter to your project before moving on.
14+
15+
# Getting Started
16+
17+
18+
## Add a dependency in you Flutter project.
19+
20+
Open you pubspec.yaml and add the following line to dependencies:
21+
22+
Before release 1.0
23+
24+
```java
25+
flutter_boost: 0.0.34
26+
```
27+
28+
29+
After Release 1.0
30+
31+
```java
32+
flutter_boost: ^0.0.39
33+
```
34+
35+
36+
## Integration with Flutter code.
37+
Add init code to you App
38+
39+
```dart
40+
void main() => runApp(MyApp());
41+
42+
class MyApp extends StatefulWidget {
43+
@override
44+
_MyAppState createState() => _MyAppState();
45+
}
46+
47+
class _MyAppState extends State<MyApp> {
48+
@override
49+
void initState() {
50+
super.initState();
51+
52+
///register page widget builders,the key is pageName
53+
FlutterBoost.singleton.registerPageBuilders({
54+
'sample://firstPage': (pageName, params, _) => FirstRouteWidget(),
55+
'sample://secondPage': (pageName, params, _) => SecondRouteWidget(),
56+
});
57+
58+
///query current top page and load it
59+
FlutterBoost.handleOnStartPage();
60+
}
61+
62+
@override
63+
Widget build(BuildContext context) => MaterialApp(
64+
title: 'Flutter Boost example',
65+
builder: FlutterBoost.init(), ///init container manager
66+
home: Container());
67+
}
68+
```
69+
70+
71+
## Integration with iOS code.
72+
73+
Use FLBFlutterAppDelegate as the superclass of your AppDelegate
74+
75+
```objc
76+
@interface AppDelegate : FLBFlutterAppDelegate <UIApplicationDelegate>
77+
@end
78+
```
79+
80+
81+
Implement FLBPlatform protocol methods for your App.
82+
83+
```objc
84+
@interface DemoRouter : NSObject<FLBPlatform>
85+
86+
@property (nonatomic,strong) UINavigationController *navigationController;
87+
88+
+ (DemoRouter *)sharedRouter;
89+
90+
@end
91+
92+
93+
@implementation DemoRouter
94+
95+
- (void)openPage:(NSString *)name
96+
params:(NSDictionary *)params
97+
animated:(BOOL)animated
98+
completion:(void (^)(BOOL))completion
99+
{
100+
if([params[@"present"] boolValue]){
101+
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
102+
[vc setName:name params:params];
103+
[self.navigationController presentViewController:vc animated:animated completion:^{}];
104+
}else{
105+
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
106+
[vc setName:name params:params];
107+
[self.navigationController pushViewController:vc animated:animated];
108+
}
109+
}
110+
111+
112+
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion
113+
{
114+
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
115+
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
116+
[vc dismissViewControllerAnimated:animated completion:^{}];
117+
}else{
118+
[self.navigationController popViewControllerAnimated:animated];
119+
}
120+
}
121+
122+
@end
123+
```
124+
125+
126+
127+
Initialize FlutterBoost with FLBPlatform at the beginning of your App.
128+
129+
```objc
130+
[FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router
131+
onStart:^(FlutterViewController *fvc) {
132+
133+
}];
134+
```
135+
136+
## Integration with Android code.
137+
138+
Init FlutterBoost in Application.onCreate() 
139+
140+
```java
141+
public class MyApplication extends FlutterApplication {
142+
@Override
143+
public void onCreate() {
144+
super.onCreate();
145+
FlutterBoostPlugin.init(new IPlatform() {
146+
@Override
147+
public Application getApplication() {
148+
return MyApplication.this;
149+
}
150+
151+
/**
152+
* get the main activity, this activity should always at the bottom of task stack.
153+
*/
154+
@Override
155+
public Activity getMainActivity() {
156+
return MainActivity.sRef.get();
157+
}
158+
159+
@Override
160+
public boolean isDebug() {
161+
return false;
162+
}
163+
164+
/**
165+
* start a new activity from flutter page, you may need a activity router.
166+
*/
167+
@Override
168+
public boolean startActivity(Context context, String url, int requestCode) {
169+
return PageRouter.openPageByUrl(context,url,requestCode);
170+
}
171+
172+
@Override
173+
public Map getSettings() {
174+
return null;
175+
}
176+
});
177+
}
178+
```
179+
180+
181+
# Basic Usage
182+
## Concepts
183+
184+
All page routing requests are being sent to the native router. Native router communicates with Native Container Manager, Native Container Manager takes care of building and destroying of Native Containers. 
185+
186+
187+
## Use Flutter Boost Native Container to show a Flutter page in native code.
188+
189+
iOS
190+
191+
```objc
192+
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
193+
[vc setName:name params:params];
194+
[self.navigationController presentViewController:vc animated:animated completion:^{}];
195+
```
196+
197+
Android
198+
199+
```java
200+
public class FlutterPageActivity extends BoostFlutterActivity {
201+
202+
@Override
203+
public void onRegisterPlugins(PluginRegistry registry) {
204+
//register flutter plugins
205+
GeneratedPluginRegistrant.registerWith(registry);
206+
}
207+
208+
@Override
209+
public String getContainerName() {
210+
//specify the page name register in FlutterBoost
211+
return "sample://firstPage";
212+
}
213+
214+
@Override
215+
public Map getContainerParams() {
216+
//params of the page
217+
Map<String,String> params = new HashMap<>();
218+
params.put("key","value");
219+
return params;
220+
}
221+
}
222+
```
223+
224+
or
225+
226+
```java
227+
public class FlutterFragment extends BoostFlutterFragment {
228+
@Override
229+
public void onRegisterPlugins(PluginRegistry registry) {
230+
GeneratedPluginRegistrant.registerWith(registry);
231+
}
232+
233+
@Override
234+
public String getContainerName() {
235+
return "sample://firstPage";
236+
}
237+
238+
@Override
239+
public Map getContainerParams() {
240+
Map<String,String> params = new HashMap<>();
241+
params.put("key","value");
242+
return params;
243+
}
244+
}
245+
```
246+
247+
248+
## Use Flutter Boost to open a page in dart code.
249+
250+
Dart
251+
252+
```objc
253+
FlutterBoost.singleton.openPage("pagename", {}, true);
254+
```
255+
256+
## Use Flutter Boost to close a page in dart code.
257+
258+
```objc
259+
FlutterBoost.singleton.closePageForContext(context);
260+
```
261+
262+
# Running the Demo
263+
Please see the example for details.
264+
265+
266+
# License
267+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
268+
269+
# Acknowledgments
270+
* Flutter

0 commit comments

Comments
 (0)