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
c7fe899c
Commit
c7fe899c
authored
Oct 14, 2019
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.9 demo优化
parent
3c3abf9f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
223 additions
and
99 deletions
+223
-99
android/src/main/java/com/idlefish/flutterboost/containers/NewBoostFlutterActivity.java
...fish/flutterboost/containers/NewBoostFlutterActivity.java
+21
-4
android/src/main/java/com/idlefish/flutterboost/containers/NewFlutterFragment.java
.../idlefish/flutterboost/containers/NewFlutterFragment.java
+13
-4
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MainActivity.java
...com/taobao/idlefish/flutterboostexample/MainActivity.java
+2
-0
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/NativePageActivity.java
...obao/idlefish/flutterboostexample/NativePageActivity.java
+3
-0
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/PageRouter.java
...a/com/taobao/idlefish/flutterboostexample/PageRouter.java
+21
-9
example/lib/main.dart
example/lib/main.dart
+5
-6
example/lib/simple_page_widgets.dart
example/lib/simple_page_widgets.dart
+158
-76
No files found.
android/src/main/java/com/idlefish/flutterboost/containers/NewBoostFlutterActivity.java
View file @
c7fe899c
...
...
@@ -31,6 +31,7 @@ import io.flutter.embedding.engine.FlutterShellArgs;
import
io.flutter.plugin.platform.PlatformPlugin
;
import
io.flutter.view.FlutterMain
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -71,7 +72,7 @@ public class NewBoostFlutterActivity extends Activity
private
final
Class
<?
extends
NewBoostFlutterActivity
>
activityClass
;
private
String
backgroundMode
=
DEFAULT_BACKGROUND_MODE
;
private
String
url
=
""
;
private
Hash
Map
params
=
new
HashMap
();
private
Map
params
=
new
HashMap
();
...
...
@@ -88,7 +89,7 @@ public class NewBoostFlutterActivity extends Activity
}
public
NewEngineIntentBuilder
params
(
@NonNull
Hash
Map
params
)
{
public
NewEngineIntentBuilder
params
(
@NonNull
Map
params
)
{
this
.
params
=
params
;
return
this
;
}
...
...
@@ -102,15 +103,30 @@ public class NewBoostFlutterActivity extends Activity
public
Intent
build
(
@NonNull
Context
context
)
{
SerializableMap
serializableMap
=
new
SerializableMap
();
serializableMap
.
setMap
(
params
);
return
new
Intent
(
context
,
activityClass
)
.
putExtra
(
EXTRA_BACKGROUND_MODE
,
backgroundMode
)
.
putExtra
(
EXTRA_DESTROY_ENGINE_WITH_ACTIVITY
,
false
)
.
putExtra
(
EXTRA_URL
,
url
)
.
putExtra
(
EXTRA_PARAMS
,
(
HashMap
)
params
);
.
putExtra
(
EXTRA_PARAMS
,
serializableMap
);
}
}
public
static
class
SerializableMap
implements
Serializable
{
private
Map
<
String
,
Object
>
map
;
public
Map
<
String
,
Object
>
getMap
()
{
return
map
;
}
public
void
setMap
(
Map
<
String
,
Object
>
map
)
{
this
.
map
=
map
;
}
}
private
FlutterActivityAndFragmentDelegate
delegate
;
...
...
@@ -476,7 +492,8 @@ public class NewBoostFlutterActivity extends Activity
public
Map
getContainerUrlParams
()
{
if
(
getIntent
().
hasExtra
(
EXTRA_PARAMS
))
{
return
(
Map
)
getIntent
().
getSerializableExtra
(
EXTRA_PARAMS
);
SerializableMap
serializableMap
=
(
SerializableMap
)
getIntent
().
getSerializableExtra
(
EXTRA_PARAMS
);
return
serializableMap
.
getMap
();
}
Map
<
String
,
String
>
params
=
new
HashMap
<>();
...
...
android/src/main/java/com/idlefish/flutterboost/containers/NewFlutterFragment.java
View file @
c7fe899c
...
...
@@ -115,7 +115,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
private
FlutterView
.
TransparencyMode
transparencyMode
=
FlutterView
.
TransparencyMode
.
transparent
;
private
boolean
shouldAttachEngineToActivity
=
true
;
private
String
url
=
""
;
private
Hash
Map
params
=
new
HashMap
();
private
Map
params
=
new
HashMap
();
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code NewFlutterFragment}.
...
...
@@ -162,7 +162,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
}
public
NewEngineFragmentBuilder
params
(
@NonNull
Hash
Map
params
)
{
public
NewEngineFragmentBuilder
params
(
@NonNull
Map
params
)
{
this
.
params
=
params
;
return
this
;
}
...
...
@@ -188,11 +188,17 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
if
(
null
!=
shellArgs
)
{
args
.
putStringArray
(
ARG_FLUTTER_INITIALIZATION_ARGS
,
shellArgs
.
toArray
());
}
NewBoostFlutterActivity
.
SerializableMap
serializableMap
=
new
NewBoostFlutterActivity
.
SerializableMap
();
serializableMap
.
setMap
(
params
);
args
.
putString
(
EXTRA_URL
,
url
);
args
.
putSerializable
(
EXTRA_PARAMS
,
(
HashMap
)
params
);
args
.
putSerializable
(
EXTRA_PARAMS
,
serializableMap
);
args
.
putString
(
ARG_FLUTTERVIEW_RENDER_MODE
,
renderMode
!=
null
?
renderMode
.
name
()
:
FlutterView
.
RenderMode
.
surface
.
name
());
args
.
putString
(
ARG_FLUTTERVIEW_TRANSPARENCY_MODE
,
transparencyMode
!=
null
?
transparencyMode
.
name
()
:
FlutterView
.
TransparencyMode
.
transparent
.
name
());
args
.
putBoolean
(
ARG_DESTROY_ENGINE_WITH_FRAGMENT
,
true
);
return
args
;
}
...
...
@@ -532,7 +538,10 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
@Override
public
Map
getContainerUrlParams
()
{
return
(
HashMap
)
getArguments
().
getSerializable
(
EXTRA_PARAMS
);
NewBoostFlutterActivity
.
SerializableMap
serializableMap
=
(
NewBoostFlutterActivity
.
SerializableMap
)
getArguments
().
getSerializable
(
EXTRA_PARAMS
);
return
serializableMap
.
getMap
();
}
/**
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MainActivity.java
View file @
c7fe899c
...
...
@@ -45,6 +45,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
public
void
onClick
(
View
v
)
{
Map
params
=
new
HashMap
();
params
.
put
(
"test1"
,
"v_test1"
);
params
.
put
(
"test2"
,
"v_test2"
);
//Add some params if needed.
if
(
v
==
mOpenNative
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
NATIVE_PAGE_URL
,
params
);
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/NativePageActivity.java
View file @
c7fe899c
...
...
@@ -33,6 +33,9 @@ public class NativePageActivity extends AppCompatActivity implements View.OnClic
@Override
public
void
onClick
(
View
v
)
{
Map
params
=
new
HashMap
();
params
.
put
(
"test1"
,
"v_test1"
);
params
.
put
(
"test2"
,
"v_test2"
);
if
(
v
==
mOpenNative
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
NATIVE_PAGE_URL
,
params
);
}
else
if
(
v
==
mOpenFlutter
)
{
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/PageRouter.java
View file @
c7fe899c
...
...
@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import
android.content.Context
;
import
android.content.Intent
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.idlefish.flutterboost.containers.NewBoostFlutterActivity
;
import
java.util.HashMap
;
...
...
@@ -10,24 +11,34 @@ import java.util.Map;
public
class
PageRouter
{
public
final
static
Map
<
String
,
String
>
pageName
=
new
HashMap
<
String
,
String
>()
{{
put
(
"sample://flutterPage1"
,
"flutterPage1"
);
put
(
"sample://flutterPage2"
,
"flutterPage2"
);
put
(
"sample://flutterPage3"
,
"flutterPage3"
);
put
(
"sample://flutterMain"
,
"flutterMain"
);
}};
public
static
final
String
NATIVE_PAGE_URL
=
"sample://nativePage"
;
public
static
final
String
FLUTTER_PAGE_URL
=
"sample://flutter
Page
"
;
public
static
final
String
FLUTTER_PAGE_URL
=
"sample://flutter
Main
"
;
public
static
final
String
FLUTTER_FRAGMENT_PAGE_URL
=
"sample://flutterFragmentPage"
;
public
static
boolean
openPageByUrl
(
Context
context
,
String
url
,
Map
params
)
{
return
openPageByUrl
(
context
,
url
,
params
,
0
);
public
static
boolean
openPageByUrl
(
Context
context
,
String
url
,
Map
params
)
{
return
openPageByUrl
(
context
,
url
,
params
,
0
);
}
public
static
boolean
openPageByUrl
(
Context
context
,
String
url
,
Map
params
,
int
requestCode
)
{
try
{
if
(
url
.
startsWith
(
FLUTTER_PAGE_URL
))
{
HashMap
p
=
new
HashMap
();
Intent
intent
=
NewBoostFlutterActivity
.
withNewEngine
().
url
(
"flutterPage"
).
params
(
p
)
String
path
=
url
.
split
(
"\\?"
)[
0
];
Log
.
i
(
"openPageByUrl"
,
path
);
try
{
if
(
pageName
.
containsKey
(
path
))
{
Intent
intent
=
NewBoostFlutterActivity
.
withNewEngine
().
url
(
pageName
.
get
(
path
)).
params
(
params
)
.
backgroundMode
(
NewBoostFlutterActivity
.
BackgroundMode
.
opaque
).
build
(
context
);
context
.
startActivity
(
intent
);
return
true
;
context
.
startActivity
(
intent
);
}
else
if
(
url
.
startsWith
(
FLUTTER_FRAGMENT_PAGE_URL
))
{
context
.
startActivity
(
new
Intent
(
context
,
FlutterFragmentPageActivity
.
class
));
return
true
;
...
...
@@ -40,5 +51,6 @@ public class PageRouter {
}
catch
(
Throwable
t
)
{
return
false
;
}
return
false
;
}
}
example/lib/main.dart
View file @
c7fe899c
...
...
@@ -17,16 +17,15 @@ class _MyAppState extends State<MyApp> {
super
.
initState
();
FlutterBoost
.
singleton
.
registerPageBuilders
({
'f
irst
'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'
second
'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'
tab
'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
'f
lutterPage1
'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'
flutterPage2
'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'
flutterPage3
'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
///可以在native层通过 getContainerParams 来传递参数
'flutter
Page
'
:
(
pageName
,
params
,
_
)
{
'flutter
Main
'
:
(
pageName
,
params
,
_
)
{
print
(
"flutterPage params:
$params
"
);
return
FlutterRouteWidget
();
return
FlutterRouteWidget
(
params:
params
);
},
});
}
...
...
example/lib/simple_page_widgets.dart
View file @
c7fe899c
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
...
...
@@ -13,8 +14,9 @@ class FirstRouteWidget extends StatelessWidget {
child:
Text
(
'Open second route'
),
onPressed:
()
{
print
(
"open second page!"
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
print
(
"call me when page is finished. did recieve second route result
$value
"
);
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage2"
).
then
((
Map
value
)
{
print
(
"call me when page is finished. did recieve second route result
$value
"
);
});
},
),
...
...
@@ -57,7 +59,7 @@ class TabRouteWidget extends StatelessWidget {
body:
Center
(
child:
RaisedButton
(
onPressed:
()
{
FlutterBoost
.
singleton
.
open
(
"s
econd
"
);
FlutterBoost
.
singleton
.
open
(
"s
ample://flutterPage2
"
);
},
child:
Text
(
'Open second route'
),
),
...
...
@@ -66,90 +68,170 @@ class TabRouteWidget extends StatelessWidget {
}
}
class
FlutterRouteWidget
extends
StatelessWidget
{
class
FlutterRouteWidget
extends
StatefulWidget
{
FlutterRouteWidget
({
this
.
params
,
this
.
message
});
final
Map
params
;
final
String
message
;
FlutterRouteWidget
({
this
.
message
});
@override
_FlutterRouteWidgetState
createState
()
=>
_FlutterRouteWidgetState
();
}
class
_FlutterRouteWidgetState
extends
State
<
FlutterRouteWidget
>
{
final
TextEditingController
_usernameController
=
TextEditingController
();
@override
Widget
build
(
BuildContext
context
)
{
final
String
message
=
widget
.
message
;
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'flutter_boost_example'
),
),
body:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
only
(
top:
80.0
),
child:
Text
(
message
??
"This is a flutter activity"
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
alignment:
AlignmentDirectional
.
center
,
),
Expanded
(
child:
Container
()),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
body:
SingleChildScrollView
(
child:
Container
(
margin:
const
EdgeInsets
.
all
(
24.0
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
only
(
top:
10.0
,
bottom:
20.0
),
child:
Text
(
message
??
"This is a flutter activity
\n
params:
${widget.params}
"
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
alignment:
AlignmentDirectional
.
center
,
),
// Expanded(child: Container()),
const
CupertinoTextField
(
prefix:
Icon
(
CupertinoIcons
.
person_solid
,
color:
CupertinoColors
.
lightBackgroundGray
,
size:
28.0
,
),
padding:
EdgeInsets
.
symmetric
(
horizontal:
6.0
,
vertical:
12.0
),
clearButtonMode:
OverlayVisibilityMode
.
editing
,
textCapitalization:
TextCapitalization
.
words
,
autocorrect:
false
,
decoration:
BoxDecoration
(
border:
Border
(
bottom:
BorderSide
(
width:
0.0
,
color:
CupertinoColors
.
inactiveGray
)),
),
placeholder:
'Name'
,
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://nativePage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter page
'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://nativePage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutterPage1
'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'push flutter widget'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
_
)
=>
PushWidget
()));
},
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter fragment page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterFragmentPage"
),
),
],
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage1"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutterPage2'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage2"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutterPage3'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage3"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'push flutter widget'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
_
)
=>
PushWidget
()));
},
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter fragment page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterFragmentPage"
),
),
],
),
),
),
);
}
...
...
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