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
f2dace06
Commit
f2dace06
authored
Apr 04, 2019
by
Yacumima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.修正返回键逻辑,存在Route的情况下默认不关闭Activity
2.增加一个pushRoute的切面能力
parent
7fe33f73
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
24 deletions
+86
-24
example/lib/main.dart
example/lib/main.dart
+30
-3
example/lib/simple_page_widgets.dart
example/lib/simple_page_widgets.dart
+10
-12
lib/container/boost_container.dart
lib/container/boost_container.dart
+23
-6
lib/container/container_manager.dart
lib/container/container_manager.dart
+9
-1
lib/flutter_boost.dart
lib/flutter_boost.dart
+14
-2
No files found.
example/lib/main.dart
View file @
f2dace06
...
...
@@ -23,8 +23,7 @@ class _MyAppState extends State<MyApp> {
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
///可以在native层通过 getContainerParams 来传递参数
'flutterPage'
:
(
pageName
,
params
,
_
){
'flutterPage'
:
(
pageName
,
params
,
_
)
{
print
(
"flutterPage params:
$params
"
);
return
FlutterRouteWidget
();
...
...
@@ -38,7 +37,35 @@ class _MyAppState extends State<MyApp> {
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Flutter Boost example'
,
builder:
FlutterBoost
.
init
(),
builder:
FlutterBoost
.
init
(
postPush:
_onRoutePushed
),
home:
Container
());
}
void
_onRoutePushed
(
String
pageName
,
String
uniqueId
,
Map
params
,
Route
route
,
Future
_
)
{
// List<OverlayEntry> newEntries = route.overlayEntries
// .map((OverlayEntry entry) => OverlayEntry(
// builder: (BuildContext context) {
// final pageWidget = entry.builder(context);
// return Stack(
// children: <Widget>[
// pageWidget,
// Positioned(
// child: Text(
// "pageName:$pageName\npageWidget:${pageWidget.toStringShort()}",
// style: TextStyle(fontSize: 12.0, color: Colors.red),
// ),
// left: 8.0,
// top: 8.0,
// )
// ],
// );
// },
// opaque: entry.opaque,
// maintainState: entry.maintainState))
// .toList(growable: true);
//
// route.overlayEntries.clear();
// route.overlayEntries.addAll(newEntries);
}
}
example/lib/simple_page_widgets.dart
View file @
f2dace06
...
...
@@ -240,15 +240,15 @@ class _PushWidgetState extends State<PushWidget> {
// TODO: implement didChangeDependencies
super
.
didChangeDependencies
();
if
(
_backPressedListenerUnsub
==
null
)
{
_backPressedListenerUnsub
=
BoostContainer
.
of
(
context
).
addBackPressedListener
(()
{
if
(
BoostContainer
.
of
(
context
).
onstage
&&
ModalRoute
.
of
(
context
).
isCurrent
)
{
Navigator
.
pop
(
context
);
}
});
}
//
if (_backPressedListenerUnsub == null) {
//
_backPressedListenerUnsub =
//
BoostContainer.of(context).addBackPressedListener(() {
//
if (BoostContainer.of(context).onstage &&
//
ModalRoute.of(context).isCurrent) {
//
Navigator.pop(context);
//
}
//
});
//
}
}
@override
...
...
@@ -260,8 +260,6 @@ class _PushWidgetState extends State<PushWidget> {
@override
Widget
build
(
BuildContext
context
)
{
return
FlutterRouteWidget
(
message:
"pushed Widget"
,
);
return
FlutterRouteWidget
(
message:
"Pushed Widget"
);
}
}
lib/container/boost_container.dart
View file @
f2dace06
...
...
@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
import
'package:flutter/material.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
import
'package:flutter_boost/container/container_manager.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter_boost/router/boost_page_route.dart'
;
...
...
@@ -124,6 +125,8 @@ class BoostContainerState extends NavigatorState {
String
get
name
=>
widget
.
settings
.
name
;
Map
get
params
=>
widget
.
settings
.
params
;
BoostContainerSettings
get
settings
=>
widget
.
settings
;
bool
get
onstage
=>
...
...
@@ -164,8 +167,7 @@ class BoostContainerState extends NavigatorState {
Logger
.
log
(
'performBackPressed'
);
if
(
_backPressedListeners
.
isEmpty
)
{
FlutterBoost
.
singleton
.
closePage
(
name
,
uniqueId
,
settings
.
params
,
animated:
false
);
pop
();
}
else
{
for
(
VoidCallback
cb
in
_backPressedListeners
)
{
cb
();
...
...
@@ -190,15 +192,30 @@ class BoostContainerState extends NavigatorState {
if
(
canPop
())
{
return
super
.
pop
(
result
);
}
else
{
if
(
BoostContainerManager
.
of
(
context
).
canPop
())
{
BoostContainerManager
.
of
(
context
).
pop
();
return
true
;
}
FlutterBoost
.
singleton
.
closePage
(
name
,
uniqueId
,
params
);
}
return
false
;
}
@override
Future
<
T
>
push
<
T
extends
Object
>(
Route
<
T
>
route
)
{
Route
<
T
>
newRoute
;
if
(
FlutterBoost
.
containerManager
.
prePushRoute
!=
null
)
{
newRoute
=
FlutterBoost
.
containerManager
.
prePushRoute
(
name
,
uniqueId
,
params
,
route
);
}
Future
<
T
>
future
=
super
.
push
<
T
>(
newRoute
??
route
);
if
(
FlutterBoost
.
containerManager
.
postPushRoute
!=
null
)
{
FlutterBoost
.
containerManager
.
postPushRoute
(
name
,
uniqueId
,
params
,
newRoute
??
route
,
future
);
}
return
future
;
}
VoidCallback
addBackPressedListener
(
VoidCallback
listener
)
{
_backPressedListeners
.
add
(
listener
);
...
...
lib/container/container_manager.dart
View file @
f2dace06
...
...
@@ -37,7 +37,11 @@ typedef BoostContainerObserver = void Function(
@immutable
class
BoostContainerManager
extends
StatefulWidget
{
final
Navigator
initNavigator
;
const
BoostContainerManager
({
Key
key
,
this
.
initNavigator
})
:
super
(
key:
key
);
final
PrePushRoute
prePushRoute
;
final
PostPushRoute
postPushRoute
;
const
BoostContainerManager
(
{
Key
key
,
this
.
initNavigator
,
this
.
prePushRoute
,
this
.
postPushRoute
})
:
super
(
key:
key
);
@override
ContainerManagerState
createState
()
=>
ContainerManagerState
();
...
...
@@ -69,6 +73,10 @@ class ContainerManagerState extends State<BoostContainerManager> {
String
_lastShownContainer
;
PrePushRoute
get
prePushRoute
=>
widget
.
prePushRoute
;
PostPushRoute
get
postPushRoute
=>
widget
.
postPushRoute
;
bool
get
foreground
=>
_foreground
;
ManagerNavigatorObserver
get
navigatorObserver
=>
_navigatorObserver
;
...
...
lib/flutter_boost.dart
View file @
f2dace06
...
...
@@ -40,6 +40,12 @@ export 'container/container_manager.dart';
typedef
Widget
PageBuilder
(
String
pageName
,
Map
params
,
String
uniqueId
);
typedef
Route
PrePushRoute
(
String
pageName
,
String
uniqueId
,
Map
params
,
Route
route
);
typedef
void
PostPushRoute
(
String
pageName
,
String
uniqueId
,
Map
params
,
Route
route
,
Future
result
);
class
FlutterBoost
{
static
final
FlutterBoost
_instance
=
FlutterBoost
();
final
GlobalKey
<
ContainerManagerState
>
containerManagerKey
=
...
...
@@ -58,14 +64,20 @@ class FlutterBoost {
static
ContainerManagerState
get
containerManager
=>
_instance
.
containerManagerKey
.
currentState
;
static
TransitionBuilder
init
([
TransitionBuilder
builder
])
{
static
TransitionBuilder
init
(
{
TransitionBuilder
builder
,
PrePushRoute
prePush
,
PostPushRoute
postPush
})
{
return
(
BuildContext
context
,
Widget
child
)
{
assert
(
child
is
Navigator
,
'child must be Navigator, what is wrong?'
);
//Logger.log('Running flutter boost opt!');
final
BoostContainerManager
manager
=
BoostContainerManager
(
key:
_instance
.
containerManagerKey
,
initNavigator:
child
);
key:
_instance
.
containerManagerKey
,
initNavigator:
child
,
prePushRoute:
prePush
,
postPushRoute:
postPush
);
if
(
builder
!=
null
)
{
return
builder
(
context
,
manager
);
...
...
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