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
1
Merge Requests
1
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
6f8de4fa
Commit
6f8de4fa
authored
Apr 12, 2020
by
AlexVincent525
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
Update format according for flutter's analysis option.
parent
1e5631a5
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
884 additions
and
778 deletions
+884
-778
analysis_options.yaml
analysis_options.yaml
+22
-6
lib/channel/boost_channel.dart
lib/channel/boost_channel.dart
+32
-26
lib/container/boost_container.dart
lib/container/boost_container.dart
+82
-72
lib/container/boost_page_route.dart
lib/container/boost_page_route.dart
+13
-14
lib/container/container_coordinator.dart
lib/container/container_coordinator.dart
+131
-112
lib/container/container_manager.dart
lib/container/container_manager.dart
+38
-30
lib/flutter_boost.dart
lib/flutter_boost.dart
+96
-74
lib/observers_holders.dart
lib/observers_holders.dart
+3
-3
lib/support/logger.dart
lib/support/logger.dart
+0
-1
pubspec.yaml
pubspec.yaml
+0
-35
test/lib/unit/boost_channel_test.dart
test/lib/unit/boost_channel_test.dart
+29
-32
test/lib/unit/boost_container_test.dart
test/lib/unit/boost_container_test.dart
+3
-3
test/lib/unit/boost_page_route_test.dart
test/lib/unit/boost_page_route_test.dart
+17
-16
test/lib/unit/container_coordinator_test.dart
test/lib/unit/container_coordinator_test.dart
+29
-28
test/lib/unit/container_manager_test.dart
test/lib/unit/container_manager_test.dart
+102
-75
test/lib/unit/flutter_boost_test.dart
test/lib/unit/flutter_boost_test.dart
+43
-35
test/lib/unit/page_widget_test.dart
test/lib/unit/page_widget_test.dart
+37
-28
test/lib/unit/page_widgets.dart
test/lib/unit/page_widgets.dart
+207
-188
No files found.
analysis_options.yaml
View file @
6f8de4fa
...
@@ -20,7 +20,10 @@
...
@@ -20,7 +20,10 @@
analyzer
:
analyzer
:
strong-mode
:
strong-mode
:
implicit-casts
:
false
implicit-dynamic
:
false
implicit-dynamic
:
false
enable-experiment
:
-
extension-methods
errors
:
errors
:
# treat missing required parameters as a warning (not a hint)
# treat missing required parameters as a warning (not a hint)
missing_required_param
:
warning
missing_required_param
:
warning
...
@@ -38,9 +41,8 @@ analyzer:
...
@@ -38,9 +41,8 @@ analyzer:
# see https://github.com/dart-lang/sdk/issues/28463
# see https://github.com/dart-lang/sdk/issues/28463
-
"
lib/i18n/messages_*.dart"
-
"
lib/i18n/messages_*.dart"
-
"
lib/src/http/**"
-
"
lib/src/http/**"
-
"
example/**"
-
"
lib/openjmu_*.dart"
-
"
example_swift/**"
-
"
test/**"
linter
:
linter
:
rules
:
rules
:
# these rules are documented on and in the same order as
# these rules are documented on and in the same order as
...
@@ -60,6 +62,7 @@ linter:
...
@@ -60,6 +62,7 @@ linter:
-
avoid_classes_with_only_static_members
-
avoid_classes_with_only_static_members
# - avoid_double_and_int_checks # only useful when targeting JS runtime
# - avoid_double_and_int_checks # only useful when targeting JS runtime
-
avoid_empty_else
-
avoid_empty_else
# - avoid_equals_and_hash_code_on_mutable_classes # not yet tested
-
avoid_field_initializers_in_const_classes
-
avoid_field_initializers_in_const_classes
-
avoid_function_literals_in_foreach_calls
-
avoid_function_literals_in_foreach_calls
# - avoid_implementing_value_types # not yet tested
# - avoid_implementing_value_types # not yet tested
...
@@ -67,7 +70,9 @@ linter:
...
@@ -67,7 +70,9 @@ linter:
# - avoid_js_rounded_ints # only useful when targeting JS runtime
# - avoid_js_rounded_ints # only useful when targeting JS runtime
-
avoid_null_checks_in_equality_operators
-
avoid_null_checks_in_equality_operators
# - avoid_positional_boolean_parameters # not yet tested
# - avoid_positional_boolean_parameters # not yet tested
# - avoid_print # not yet tested
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
# - avoid_redundant_argument_values # not yet tested
-
avoid_relative_lib_imports
-
avoid_relative_lib_imports
-
avoid_renaming_method_parameters
-
avoid_renaming_method_parameters
-
avoid_return_types_on_setters
-
avoid_return_types_on_setters
...
@@ -81,9 +86,12 @@ linter:
...
@@ -81,9 +86,12 @@ linter:
-
avoid_slow_async_io
-
avoid_slow_async_io
-
avoid_types_as_parameter_names
-
avoid_types_as_parameter_names
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
# - avoid_unnecessary_containers # not yet tested
-
avoid_unused_constructor_parameters
-
avoid_unused_constructor_parameters
-
avoid_void_async
-
avoid_void_async
# - avoid_web_libraries_in_flutter # not yet tested
-
await_only_futures
-
await_only_futures
-
camel_case_extensions
-
camel_case_types
-
camel_case_types
-
cancel_subscriptions
-
cancel_subscriptions
# - cascade_invocations # not yet tested
# - cascade_invocations # not yet tested
...
@@ -109,8 +117,11 @@ linter:
...
@@ -109,8 +117,11 @@ linter:
# - lines_longer_than_80_chars # not yet tested
# - lines_longer_than_80_chars # not yet tested
-
list_remove_unrelated_type
-
list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
# - missing_whitespace_between_adjacent_strings # not yet tested
-
no_adjacent_strings_in_list
-
no_adjacent_strings_in_list
-
no_duplicate_case_values
-
no_duplicate_case_values
# - no_logic_in_create_state # not yet tested
# - no_runtimeType_toString # not yet tested
-
non_constant_identifier_names
-
non_constant_identifier_names
# - null_closures # not yet tested
# - null_closures # not yet tested
# - omit_local_variable_types # opposite of always_specify_types
# - omit_local_variable_types # opposite of always_specify_types
...
@@ -136,9 +147,9 @@ linter:
...
@@ -136,9 +147,9 @@ linter:
-
prefer_equal_for_default_values
-
prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
-
prefer_final_fields
-
prefer_final_fields
# - prefer_final_in_for_each # not yet tested
-
prefer_final_in_for_each
-
prefer_final_locals
-
prefer_final_locals
# - prefer_for_elements_to_map_fromIterable # not yet tested
-
prefer_for_elements_to_map_fromIterable
-
prefer_foreach
-
prefer_foreach
# - prefer_function_declarations_over_variables # not yet tested
# - prefer_function_declarations_over_variables # not yet tested
-
prefer_generic_function_type_aliases
-
prefer_generic_function_type_aliases
...
@@ -150,9 +161,11 @@ linter:
...
@@ -150,9 +161,11 @@ linter:
# - prefer_interpolation_to_compose_strings # not yet tested
# - prefer_interpolation_to_compose_strings # not yet tested
-
prefer_is_empty
-
prefer_is_empty
-
prefer_is_not_empty
-
prefer_is_not_empty
-
prefer_is_not_operator
-
prefer_iterable_whereType
-
prefer_iterable_whereType
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
# - prefer_relative_imports # not yet tested
-
prefer_single_quotes
-
prefer_single_quotes
-
prefer_spread_collections
-
prefer_spread_collections
-
prefer_typing_uninitialized_variables
-
prefer_typing_uninitialized_variables
...
@@ -173,6 +186,7 @@ linter:
...
@@ -173,6 +186,7 @@ linter:
# - unnecessary_await_in_return # not yet tested
# - unnecessary_await_in_return # not yet tested
-
unnecessary_brace_in_string_interps
-
unnecessary_brace_in_string_interps
-
unnecessary_const
-
unnecessary_const
# - unnecessary_final # conflicts with prefer_final_locals
-
unnecessary_getters_setters
-
unnecessary_getters_setters
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
-
unnecessary_new
-
unnecessary_new
...
@@ -181,14 +195,16 @@ linter:
...
@@ -181,14 +195,16 @@ linter:
-
unnecessary_overrides
-
unnecessary_overrides
-
unnecessary_parenthesis
-
unnecessary_parenthesis
-
unnecessary_statements
-
unnecessary_statements
# - unnecessary_string_interpolations
-
unnecessary_this
-
unnecessary_this
-
unrelated_type_equality_checks
-
unrelated_type_equality_checks
# - unsafe_html # not yet tested
# - unsafe_html # not yet tested
-
use_full_hex_values_for_flutter_colors
-
use_full_hex_values_for_flutter_colors
# - use_function_type_syntax_for_parameters # not yet tested
# - use_function_type_syntax_for_parameters # not yet tested
# - use_key_in_widget_constructors # not yet tested
-
use_rethrow_when_possible
-
use_rethrow_when_possible
# - use_setters_to_change_properties # not yet tested
# - use_setters_to_change_properties # not yet tested
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
-
valid_regexps
-
valid_regexps
# - void_checks # not yet tested
-
void_checks
\ No newline at end of file
lib/channel/boost_channel.dart
View file @
6f8de4fa
...
@@ -24,30 +24,30 @@
...
@@ -24,30 +24,30 @@
import
'dart:async'
;
import
'dart:async'
;
import
'dart:ui'
;
import
'dart:ui'
;
import
'package:flutter/services.dart'
;
typedef
Future
<
dynamic
>
EventListener
(
String
name
,
Map
arguments
);
import
'package:flutter/services.dart'
;
typedef
Future
<
dynamic
>
MethodHandler
(
MethodCall
call
);
class
BoostChannel
{
typedef
EventListener
=
Future
<
dynamic
>
Function
(
final
MethodChannel
_methodChannel
=
MethodChannel
(
"flutter_boost"
);
String
name
,
Map
<
String
,
dynamic
>
arguments
);
final
Map
<
String
,
List
<
EventListener
>>
_eventListeners
=
Map
();
typedef
MethodHandler
=
Future
<
dynamic
>
Function
(
MethodCall
call
);
final
Set
<
MethodHandler
>
_methodHandlers
=
Set
();
class
BoostChannel
{
BoostChannel
()
{
BoostChannel
()
{
_methodChannel
.
setMethodCallHandler
((
MethodCall
call
)
{
_methodChannel
.
setMethodCallHandler
((
MethodCall
call
)
{
if
(
call
.
method
==
"__event__"
)
{
if
(
call
.
method
==
'__event__'
)
{
String
name
=
call
.
arguments
[
"name"
];
final
String
name
=
call
.
arguments
[
'name'
]
as
String
;
Map
arg
=
call
.
arguments
[
"arguments"
];
final
Map
<
String
,
dynamic
>
arg
=
List
<
EventListener
>
list
=
_eventListeners
[
name
];
(
call
.
arguments
[
'arguments'
]
as
Map
<
dynamic
,
dynamic
>)
?.
cast
<
String
,
dynamic
>();
final
List
<
EventListener
>
list
=
_eventListeners
[
name
];
if
(
list
!=
null
)
{
if
(
list
!=
null
)
{
for
(
EventListener
l
in
list
)
{
for
(
final
EventListener
l
in
list
)
{
l
(
name
,
arg
);
l
(
name
,
arg
);
}
}
}
}
}
else
{
}
else
{
for
(
MethodHandler
handler
in
_methodHandlers
)
{
for
(
final
MethodHandler
handler
in
_methodHandlers
)
{
handler
(
call
);
handler
(
call
);
}
}
}
}
...
@@ -56,37 +56,41 @@ class BoostChannel {
...
@@ -56,37 +56,41 @@ class BoostChannel {
});
});
}
}
void
sendEvent
(
String
name
,
Map
arguments
)
{
final
MethodChannel
_methodChannel
=
const
MethodChannel
(
'flutter_boost'
);
final
Map
<
String
,
List
<
EventListener
>>
_eventListeners
=
<
String
,
List
<
EventListener
>>{};
final
Set
<
MethodHandler
>
_methodHandlers
=
<
MethodHandler
>{};
void
sendEvent
(
String
name
,
Map
<
String
,
dynamic
>
arguments
)
{
if
(
name
==
null
)
{
if
(
name
==
null
)
{
return
;
return
;
}
}
if
(
arguments
==
null
)
{
arguments
??=
<
String
,
dynamic
>{};
arguments
=
Map
<
dynamic
,
dynamic
>();
}
Map
msg
=
Map
<
dynamic
,
dynamic
>()
;
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{}
;
msg
[
"name"
]
=
name
;
msg
[
'name'
]
=
name
;
msg
[
"arguments"
]
=
arguments
;
msg
[
'arguments'
]
=
arguments
;
_methodChannel
.
invokeMethod
<
dynamic
>(
"__event__"
,
msg
);
_methodChannel
.
invokeMethod
<
dynamic
>(
'__event__'
,
msg
);
}
}
Future
<
T
>
invokeMethod
<
T
>(
String
method
,
[
dynamic
arguments
])
async
{
Future
<
T
>
invokeMethod
<
T
>(
String
method
,
[
dynamic
arguments
])
async
{
assert
(
method
!=
"__event__"
);
assert
(
method
!=
'__event__'
);
return
_methodChannel
.
invokeMethod
<
T
>(
method
,
arguments
);
return
_methodChannel
.
invokeMethod
<
T
>(
method
,
arguments
);
}
}
Future
<
List
<
T
>>
invokeListMethod
<
T
>(
String
method
,
Future
<
List
<
T
>>
invokeListMethod
<
T
>(
String
method
,
[
dynamic
arguments
])
async
{
[
dynamic
arguments
])
async
{
assert
(
method
!=
"__event__"
);
assert
(
method
!=
'__event__'
);
return
_methodChannel
.
invokeListMethod
<
T
>(
method
,
arguments
);
return
_methodChannel
.
invokeListMethod
<
T
>(
method
,
arguments
);
}
}
Future
<
Map
<
K
,
V
>>
invokeMapMethod
<
K
,
V
>(
String
method
,
Future
<
Map
<
K
,
V
>>
invokeMapMethod
<
K
,
V
>(
String
method
,
[
dynamic
arguments
])
async
{
[
dynamic
arguments
])
async
{
assert
(
method
!=
"__event__"
);
assert
(
method
!=
'__event__'
);
return
_methodChannel
.
invokeMapMethod
<
K
,
V
>(
method
,
arguments
);
return
_methodChannel
.
invokeMapMethod
<
K
,
V
>(
method
,
arguments
);
}
}
...
@@ -94,9 +98,11 @@ class BoostChannel {
...
@@ -94,9 +98,11 @@ class BoostChannel {
VoidCallback
addEventListener
(
String
name
,
EventListener
listener
)
{
VoidCallback
addEventListener
(
String
name
,
EventListener
listener
)
{
assert
(
name
!=
null
&&
listener
!=
null
);
assert
(
name
!=
null
&&
listener
!=
null
);
List
<
EventListener
>
list
=
_eventListeners
[
name
];
List
<
EventListener
>
list
;
list
=
_eventListeners
[
name
];
if
(
list
==
null
)
{
if
(
list
==
null
)
{
list
=
List
()
;
list
=
<
EventListener
>[]
;
_eventListeners
[
name
]
=
list
;
_eventListeners
[
name
]
=
list
;
}
}
...
...
lib/container/boost_container.dart
View file @
6f8de4fa
...
@@ -22,10 +22,11 @@
...
@@ -22,10 +22,11 @@
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'container_manager.dart'
;
import
'../flutter_boost.dart'
;
import
'../flutter_boost.dart'
;
import
'boost_page_route.dart'
;
import
'../support/logger.dart'
;
import
'../support/logger.dart'
;
import
'boost_page_route.dart'
;
import
'container_manager.dart'
;
enum
ContainerLifeCycle
{
enum
ContainerLifeCycle
{
Init
,
Init
,
...
@@ -37,28 +38,31 @@ enum ContainerLifeCycle {
...
@@ -37,28 +38,31 @@ enum ContainerLifeCycle {
Foreground
Foreground
}
}
typedef
void
BoostContainerLifeCycleObserver
(
typedef
BoostContainerLifeCycleObserver
=
void
Function
(
ContainerLifeCycle
state
,
BoostContainerSettings
settings
);
ContainerLifeCycle
state
,
BoostContainerSettings
settings
,
);
class
BoostContainer
extends
Navigator
{
class
BoostContainer
extends
Navigator
{
final
BoostContainerSettings
settings
;
const
BoostContainer
({
GlobalKey
<
BoostContainerState
>
key
,
const
BoostContainer
(
{
GlobalKey
<
BoostContainerState
>
key
,
this
.
settings
=
const
BoostContainerSettings
(),
this
.
settings
=
const
BoostContainerSettings
(),
String
initialRoute
,
String
initialRoute
,
RouteFactory
onGenerateRoute
,
RouteFactory
onGenerateRoute
,
RouteFactory
onUnknownRoute
,
RouteFactory
onUnknownRoute
,
List
<
NavigatorObserver
>
observers
})
List
<
NavigatorObserver
>
observers
,
:
super
(
})
:
super
(
key:
key
,
key:
key
,
initialRoute:
initialRoute
,
initialRoute:
initialRoute
,
onGenerateRoute:
onGenerateRoute
,
onGenerateRoute:
onGenerateRoute
,
onUnknownRoute:
onUnknownRoute
,
onUnknownRoute:
onUnknownRoute
,
observers:
observers
);
observers:
observers
,
);
factory
BoostContainer
.
copy
(
Navigator
navigator
,
factory
BoostContainer
.
copy
(
[
BoostContainerSettings
settings
=
const
BoostContainerSettings
()])
=>
Navigator
navigator
,
[
BoostContainerSettings
settings
=
const
BoostContainerSettings
(),
])
=>
BoostContainer
(
BoostContainer
(
key:
GlobalKey
<
BoostContainerState
>(),
key:
GlobalKey
<
BoostContainerState
>(),
settings:
settings
,
settings:
settings
,
...
@@ -69,7 +73,9 @@ class BoostContainer extends Navigator {
...
@@ -69,7 +73,9 @@ class BoostContainer extends Navigator {
);
);
factory
BoostContainer
.
obtain
(
factory
BoostContainer
.
obtain
(
Navigator
navigator
,
BoostContainerSettings
settings
)
=>
Navigator
navigator
,
BoostContainerSettings
settings
,
)
=>
BoostContainer
(
BoostContainer
(
key:
GlobalKey
<
BoostContainerState
>(),
key:
GlobalKey
<
BoostContainerState
>(),
settings:
settings
,
settings:
settings
,
...
@@ -81,7 +87,8 @@ class BoostContainer extends Navigator {
...
@@ -81,7 +87,8 @@ class BoostContainer extends Navigator {
uniqueId:
settings
.
uniqueId
,
uniqueId:
settings
.
uniqueId
,
animated:
false
,
animated:
false
,
settings:
routeSettings
,
settings:
routeSettings
,
builder:
settings
.
builder
);
builder:
settings
.
builder
,
);
}
else
{
}
else
{
return
navigator
.
onGenerateRoute
(
routeSettings
);
return
navigator
.
onGenerateRoute
(
routeSettings
);
}
}
...
@@ -90,7 +97,10 @@ class BoostContainer extends Navigator {
...
@@ -90,7 +97,10 @@ class BoostContainer extends Navigator {
ContainerNavigatorObserver
.
bindContainerManager
(),
ContainerNavigatorObserver
.
bindContainerManager
(),
HeroController
(),
HeroController
(),
],
],
onUnknownRoute:
navigator
.
onUnknownRoute
);
onUnknownRoute:
navigator
.
onUnknownRoute
,
);
final
BoostContainerSettings
settings
;
@override
@override
BoostContainerState
createState
()
=>
BoostContainerState
();
BoostContainerState
createState
()
=>
BoostContainerState
();
...
@@ -121,7 +131,7 @@ class BoostContainerState extends NavigatorState {
...
@@ -121,7 +131,7 @@ class BoostContainerState extends NavigatorState {
String
get
name
=>
widget
.
settings
.
name
;
String
get
name
=>
widget
.
settings
.
name
;
Map
get
params
=>
widget
.
settings
.
params
;
Map
<
String
,
dynamic
>
get
params
=>
widget
.
settings
.
params
;
BoostContainerSettings
get
settings
=>
widget
.
settings
;
BoostContainerSettings
get
settings
=>
widget
.
settings
;
...
@@ -138,7 +148,7 @@ class BoostContainerState extends NavigatorState {
...
@@ -138,7 +148,7 @@ class BoostContainerState extends NavigatorState {
ContainerNavigatorObserver
findContainerNavigatorObserver
(
ContainerNavigatorObserver
findContainerNavigatorObserver
(
Navigator
navigator
)
{
Navigator
navigator
)
{
for
(
NavigatorObserver
observer
in
navigator
.
observers
)
{
for
(
final
NavigatorObserver
observer
in
navigator
.
observers
)
{
if
(
observer
is
ContainerNavigatorObserver
)
{
if
(
observer
is
ContainerNavigatorObserver
)
{
return
observer
;
return
observer
;
}
}
...
@@ -153,11 +163,6 @@ class BoostContainerState extends NavigatorState {
...
@@ -153,11 +163,6 @@ class BoostContainerState extends NavigatorState {
backPressedHandler
=
()
=>
maybePop
();
backPressedHandler
=
()
=>
maybePop
();
}
}
@override
void
didUpdateWidget
(
Navigator
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
}
@override
@override
void
dispose
()
{
void
dispose
()
{
routerHistory
.
clear
();
routerHistory
.
clear
();
...
@@ -172,7 +177,7 @@ class BoostContainerState extends NavigatorState {
...
@@ -172,7 +177,7 @@ class BoostContainerState extends NavigatorState {
@override
@override
Future
<
bool
>
maybePop
<
T
extends
Object
>([
T
result
])
async
{
Future
<
bool
>
maybePop
<
T
extends
Object
>([
T
result
])
async
{
final
Route
<
T
>
route
=
routerHistory
.
last
;
final
Route
<
T
>
route
=
routerHistory
.
last
as
Route
<
T
>
;
final
RoutePopDisposition
disposition
=
await
route
.
willPop
();
final
RoutePopDisposition
disposition
=
await
route
.
willPop
();
if
(
mounted
)
{
if
(
mounted
)
{
switch
(
disposition
)
{
switch
(
disposition
)
{
...
@@ -216,10 +221,10 @@ class BoostContainerState extends NavigatorState {
...
@@ -216,10 +221,10 @@ class BoostContainerState extends NavigatorState {
Route
<
T
>
newRoute
;
Route
<
T
>
newRoute
;
if
(
FlutterBoost
.
containerManager
.
prePushRoute
!=
null
)
{
if
(
FlutterBoost
.
containerManager
.
prePushRoute
!=
null
)
{
newRoute
=
FlutterBoost
.
containerManager
newRoute
=
FlutterBoost
.
containerManager
.
prePushRoute
(
name
,
uniqueId
,
params
,
route
);
.
prePushRoute
<
T
>
(
name
,
uniqueId
,
params
,
route
);
}
}
Future
<
T
>
future
=
super
.
push
<
T
>(
newRoute
??
route
);
final
Future
<
T
>
future
=
super
.
push
<
T
>(
newRoute
??
route
);
routerHistory
.
add
(
route
);
routerHistory
.
add
(
route
);
...
@@ -233,25 +238,30 @@ class BoostContainerState extends NavigatorState {
...
@@ -233,25 +238,30 @@ class BoostContainerState extends NavigatorState {
VoidCallback
addLifeCycleObserver
(
BoostContainerLifeCycleObserver
observer
)
{
VoidCallback
addLifeCycleObserver
(
BoostContainerLifeCycleObserver
observer
)
{
return
FlutterBoost
.
singleton
.
addBoostContainerLifeCycleObserver
(
return
FlutterBoost
.
singleton
.
addBoostContainerLifeCycleObserver
(
(
ContainerLifeCycle
state
,
BoostContainerSettings
settings
)
{
(
ContainerLifeCycle
state
,
BoostContainerSettings
settings
,
)
{
if
(
settings
.
uniqueId
==
uniqueId
)
{
if
(
settings
.
uniqueId
==
uniqueId
)
{
observer
(
state
,
settings
);
observer
(
state
,
settings
);
}
}
});
},
);
}
}
}
}
class
BoostContainerSettings
{
class
BoostContainerSettings
{
const
BoostContainerSettings
({
this
.
uniqueId
=
'default'
,
this
.
name
=
'default'
,
this
.
params
,
this
.
builder
,
});
final
String
uniqueId
;
final
String
uniqueId
;
final
String
name
;
final
String
name
;
final
Map
params
;
final
Map
<
String
,
dynamic
>
params
;
final
WidgetBuilder
builder
;
final
WidgetBuilder
builder
;
const
BoostContainerSettings
(
{
this
.
uniqueId
=
'default'
,
this
.
name
=
'default'
,
this
.
params
,
this
.
builder
});
}
}
class
ContainerElement
extends
StatefulElement
{
class
ContainerElement
extends
StatefulElement
{
...
@@ -259,13 +269,13 @@ class ContainerElement extends StatefulElement {
...
@@ -259,13 +269,13 @@ class ContainerElement extends StatefulElement {
}
}
class
ContainerNavigatorObserver
extends
NavigatorObserver
{
class
ContainerNavigatorObserver
extends
NavigatorObserver
{
static
final
Set
<
NavigatorObserver
>
boostObservers
=
Set
<
NavigatorObserver
>();
ContainerNavigatorObserver
();
ContainerNavigatorObserver
();
factory
ContainerNavigatorObserver
.
bindContainerManager
()
=>
factory
ContainerNavigatorObserver
.
bindContainerManager
()
=>
ContainerNavigatorObserver
();
ContainerNavigatorObserver
();
static
final
Set
<
NavigatorObserver
>
boostObservers
=
<
NavigatorObserver
>{};
VoidCallback
addBoostNavigatorObserver
(
NavigatorObserver
observer
)
{
VoidCallback
addBoostNavigatorObserver
(
NavigatorObserver
observer
)
{
boostObservers
.
add
(
observer
);
boostObservers
.
add
(
observer
);
...
@@ -278,28 +288,28 @@ class ContainerNavigatorObserver extends NavigatorObserver {
...
@@ -278,28 +288,28 @@ class ContainerNavigatorObserver extends NavigatorObserver {
@override
@override
void
didPush
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didPush
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
for
(
NavigatorObserver
observer
in
boostObservers
)
{
for
(
final
NavigatorObserver
observer
in
boostObservers
)
{
observer
.
didPush
(
route
,
previousRoute
);
observer
.
didPush
(
route
,
previousRoute
);
}
}
}
}
@override
@override
void
didPop
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didPop
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
for
(
NavigatorObserver
observer
in
boostObservers
)
{
for
(
final
NavigatorObserver
observer
in
boostObservers
)
{
observer
.
didPop
(
route
,
previousRoute
);
observer
.
didPop
(
route
,
previousRoute
);
}
}
}
}
@override
@override
void
didRemove
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didRemove
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
for
(
NavigatorObserver
observer
in
boostObservers
)
{
for
(
final
NavigatorObserver
observer
in
boostObservers
)
{
observer
.
didRemove
(
route
,
previousRoute
);
observer
.
didRemove
(
route
,
previousRoute
);
}
}
}
}
@override
@override
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
for
(
NavigatorObserver
observer
in
boostObservers
)
{
for
(
final
NavigatorObserver
observer
in
boostObservers
)
{
observer
.
didReplace
(
newRoute:
newRoute
,
oldRoute:
oldRoute
);
observer
.
didReplace
(
newRoute:
newRoute
,
oldRoute:
oldRoute
);
}
}
}
}
...
...
lib/container/boost_page_route.dart
View file @
6f8de4fa
...
@@ -25,26 +25,25 @@
...
@@ -25,26 +25,25 @@
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
typedef
Widget
PageBuilder
(
String
pageName
,
Map
params
,
String
uniqueId
);
typedef
PageBuilder
=
Widget
Function
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
uniqueId
);
class
BoostPageRoute
<
T
>
extends
MaterialPageRoute
<
T
>
{
class
BoostPageRoute
<
T
>
extends
MaterialPageRoute
<
T
>
{
BoostPageRoute
({
this
.
pageName
,
this
.
params
,
this
.
uniqueId
,
this
.
animated
,
WidgetBuilder
builder
,
RouteSettings
settings
,
})
:
super
(
builder:
builder
,
settings:
settings
);
final
String
pageName
;
final
String
pageName
;
final
String
uniqueId
;
final
String
uniqueId
;
final
Map
params
;
final
Map
<
String
,
dynamic
>
params
;
final
bool
animated
;
final
bool
animated
;
final
WidgetBuilder
builder
;
final
RouteSettings
settings
;
final
Set
<
VoidCallback
>
backPressedListeners
=
Set
<
VoidCallback
>();
final
Set
<
VoidCallback
>
backPressedListeners
=
<
VoidCallback
>{};
BoostPageRoute
(
{
this
.
pageName
,
this
.
params
,
this
.
uniqueId
,
this
.
animated
,
this
.
builder
,
this
.
settings
})
:
super
(
builder:
builder
,
settings:
settings
);
static
BoostPageRoute
<
T
>
of
<
T
>(
BuildContext
context
)
{
static
BoostPageRoute
<
T
>
of
<
T
>(
BuildContext
context
)
{
final
Route
<
T
>
route
=
ModalRoute
.
of
(
context
);
final
Route
<
T
>
route
=
ModalRoute
.
of
(
context
);
...
...
lib/container/container_coordinator.dart
View file @
6f8de4fa
...
@@ -27,12 +27,25 @@ import 'dart:io';
...
@@ -27,12 +27,25 @@ import 'dart:io';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/semantics.dart'
;
import
'package:flutter/semantics.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'../channel/boost_channel.dart'
;
import
'../channel/boost_channel.dart'
;
import
'boost_container.dart'
;
import
'../flutter_boost.dart'
;
import
'../flutter_boost.dart'
;
import
'../support/logger.dart'
;
import
'../support/logger.dart'
;
import
'boost_container.dart'
;
class
ContainerCoordinator
{
class
ContainerCoordinator
{
ContainerCoordinator
(
BoostChannel
channel
)
:
assert
(
_instance
==
null
)
{
_instance
=
this
;
channel
..
addEventListener
(
'lifecycle'
,
(
String
name
,
Map
<
String
,
dynamic
>
arguments
)
=>
_onChannelEvent
(
arguments
),
)
..
addMethodHandler
((
MethodCall
call
)
=>
_onMethodCall
(
call
));
}
static
ContainerCoordinator
get
singleton
=>
_instance
;
static
ContainerCoordinator
get
singleton
=>
_instance
;
static
ContainerCoordinator
_instance
;
static
ContainerCoordinator
_instance
;
...
@@ -40,19 +53,11 @@ class ContainerCoordinator {
...
@@ -40,19 +53,11 @@ class ContainerCoordinator {
final
Map
<
String
,
PageBuilder
>
_pageBuilders
=
<
String
,
PageBuilder
>{};
final
Map
<
String
,
PageBuilder
>
_pageBuilders
=
<
String
,
PageBuilder
>{};
PageBuilder
_defaultPageBuilder
;
PageBuilder
_defaultPageBuilder
;
ContainerCoordinator
(
BoostChannel
channel
)
{
assert
(
_instance
==
null
);
_instance
=
this
;
channel
.
addEventListener
(
"lifecycle"
,
(
String
name
,
Map
arguments
)
=>
_onChannelEvent
(
arguments
));
channel
.
addMethodHandler
((
MethodCall
call
)
=>
_onMethodCall
(
call
));
}
BoostContainerSettings
_createContainerSettings
(
BoostContainerSettings
_createContainerSettings
(
String
name
,
Map
params
,
String
pageId
)
{
String
name
,
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
Widget
page
;
Widget
page
;
final
BoostContainerSettings
routeSettings
=
BoostContainerSettings
(
final
BoostContainerSettings
routeSettings
=
BoostContainerSettings
(
...
@@ -60,12 +65,12 @@ class ContainerCoordinator {
...
@@ -60,12 +65,12 @@ class ContainerCoordinator {
name:
name
,
name:
name
,
params:
params
,
params:
params
,
builder:
(
BuildContext
ctx
)
{
builder:
(
BuildContext
ctx
)
{
//Try to build a page using keyed builder.
//
Try to build a page using keyed builder.
if
(
_pageBuilders
[
name
]
!=
null
)
{
if
(
_pageBuilders
[
name
]
!=
null
)
{
page
=
_pageBuilders
[
name
](
name
,
params
,
pageId
);
page
=
_pageBuilders
[
name
](
name
,
params
,
pageId
);
}
}
//Build a page using default builder.
//
Build a page using default builder.
if
(
page
==
null
&&
_defaultPageBuilder
!=
null
)
{
if
(
page
==
null
&&
_defaultPageBuilder
!=
null
)
{
page
=
_defaultPageBuilder
(
name
,
params
,
pageId
);
page
=
_defaultPageBuilder
(
name
,
params
,
pageId
);
}
}
...
@@ -79,12 +84,12 @@ class ContainerCoordinator {
...
@@ -79,12 +84,12 @@ class ContainerCoordinator {
return
routeSettings
;
return
routeSettings
;
}
}
//Register a default page builder.
//
/
Register a default page builder.
void
registerDefaultPageBuilder
(
PageBuilder
builder
)
{
void
registerDefaultPageBuilder
(
PageBuilder
builder
)
{
_defaultPageBuilder
=
builder
;
_defaultPageBuilder
=
builder
;
}
}
//Register page builder for a key.
//
/
Register page builder for a key.
void
registerPageBuilder
(
String
pageName
,
PageBuilder
builder
)
{
void
registerPageBuilder
(
String
pageName
,
PageBuilder
builder
)
{
if
(
pageName
!=
null
&&
builder
!=
null
)
{
if
(
pageName
!=
null
&&
builder
!=
null
)
{
_pageBuilders
[
pageName
]
=
builder
;
_pageBuilders
[
pageName
]
=
builder
;
...
@@ -98,41 +103,35 @@ class ContainerCoordinator {
...
@@ -98,41 +103,35 @@ class ContainerCoordinator {
}
}
Future
<
dynamic
>
_onChannelEvent
(
dynamic
event
)
{
Future
<
dynamic
>
_onChannelEvent
(
dynamic
event
)
{
if
(
event
is
Map
)
{
if
(
event
is
Map
<
String
,
dynamic
>
)
{
Map
map
=
event
;
final
Map
<
String
,
dynamic
>
map
=
event
;
final
String
type
=
map
[
'type'
];
final
String
type
=
map
[
'type'
]
as
String
;
Logger
.
log
(
'onEvent
$type
'
);
Logger
.
log
(
'onEvent
$type
'
);
switch
(
type
)
{
switch
(
type
)
{
//Handler back key pressed event.
//
Handler back key pressed event.
case
'backPressedCallback'
:
case
'backPressedCallback'
:
{
final
String
id
=
map
[
'uniqueId'
]
as
String
;
final
String
id
=
map
[
'uniqueId'
];
FlutterBoost
.
containerManager
FlutterBoost
.
containerManager
?.
containerStateOf
(
id
)
?.
containerStateOf
(
id
)
?.
performBackPressed
();
?.
performBackPressed
();
}
break
;
break
;
//
Enter foregrou
d
//
Enter foregroun
d
case
'foreground'
:
case
'foreground'
:
{
FlutterBoost
.
containerManager
?.
setForeground
();
FlutterBoost
.
containerManager
?.
setForeground
();
}
break
;
break
;
//Enter background
//
Enter background
case
'background'
:
case
'background'
:
{
FlutterBoost
.
containerManager
?.
setBackground
();
FlutterBoost
.
containerManager
?.
setBackground
();
}
break
;
break
;
//Schedule a frame.
//
Schedule a frame.
case
'scheduleFrame'
:
case
'scheduleFrame'
:
{
WidgetsBinding
.
instance
.
scheduleForcedFrame
();
WidgetsBinding
.
instance
.
scheduleForcedFrame
();
Future
<
dynamic
>.
delayed
(
Duration
(
milliseconds:
250
),
Future
<
dynamic
>.
delayed
(
()
=>
WidgetsBinding
.
instance
.
scheduleFrame
());
const
Duration
(
milliseconds:
250
),
}
()
=>
WidgetsBinding
.
instance
.
scheduleFrame
(),
);
break
;
break
;
}
}
}
}
...
@@ -141,72 +140,52 @@ class ContainerCoordinator {
...
@@ -141,72 +140,52 @@ class ContainerCoordinator {
}
}
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
Logger
.
log
(
"onMetohdCall
${call.method}
"
);
Logger
.
log
(
'onMetohdCall
${call.method}
'
);
final
String
pageName
=
call
.
arguments
[
'pageName'
]
as
String
;
final
Map
<
String
,
dynamic
>
params
=
(
call
.
arguments
[
'params'
]
as
Map
<
dynamic
,
dynamic
>)
?.
cast
<
String
,
dynamic
>();
final
String
uniqueId
=
call
.
arguments
[
'uniqueId'
]
as
String
;
switch
(
call
.
method
)
{
switch
(
call
.
method
)
{
case
"didInitPageContainer"
:
case
'didInitPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
_nativeContainerDidInit
(
pageName
,
params
,
uniqueId
);
_nativeContainerDidInit
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"willShowPageContainer"
:
case
'willShowPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
_nativeContainerWillShow
(
pageName
,
params
,
uniqueId
);
_nativeContainerWillShow
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"didShowPageContainer"
:
case
'didShowPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
nativeContainerDidShow
(
pageName
,
params
,
uniqueId
);
nativeContainerDidShow
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"willDisappearPageContainer"
:
case
'willDisappearPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
_nativeContainerWillDisappear
(
pageName
,
params
,
uniqueId
);
_nativeContainerWillDisappear
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"didDisappearPageContainer"
:
case
'didDisappearPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
_nativeContainerDidDisappear
(
pageName
,
params
,
uniqueId
);
_nativeContainerDidDisappear
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"willDeallocPageContainer"
:
case
'willDeallocPageContainer'
:
{
String
pageName
=
call
.
arguments
[
"pageName"
];
Map
params
=
call
.
arguments
[
"params"
];
String
uniqueId
=
call
.
arguments
[
"uniqueId"
];
_nativeContainerWillDealloc
(
pageName
,
params
,
uniqueId
);
_nativeContainerWillDealloc
(
pageName
,
params
,
uniqueId
);
}
break
;
break
;
case
"onNativePageResult"
:
case
'onNativePageResult'
:
{}
break
;
break
;
}
}
return
Future
<
dynamic
>(()
{});
return
Future
<
dynamic
>(()
{});
}
}
bool
_nativeContainerWillShow
(
String
name
,
Map
params
,
String
pageId
)
{
bool
_nativeContainerWillShow
(
String
name
,
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
if
(
FlutterBoost
.
containerManager
?.
containsContainer
(
pageId
)
!=
true
)
{
if
(
FlutterBoost
.
containerManager
?.
containsContainer
(
pageId
)
!=
true
)
{
FlutterBoost
.
containerManager
FlutterBoost
.
containerManager
?.
pushContainer
(
?.
pushContainer
(
_createContainerSettings
(
name
,
params
,
pageId
));
_createContainerSettings
(
name
,
params
,
pageId
),
);
}
}
//
TODO,
需要验证android代码是否也可以移到这里
//
TODO(unknown):
需要验证android代码是否也可以移到这里
if
(
Platform
.
isIOS
)
{
if
(
Platform
.
isIOS
)
{
try
{
try
{
final
SemanticsOwner
owner
=
final
SemanticsOwner
owner
=
...
@@ -221,11 +200,15 @@ class ContainerCoordinator {
...
@@ -221,11 +200,15 @@ class ContainerCoordinator {
return
true
;
return
true
;
}
}
bool
nativeContainerDidShow
(
String
name
,
Map
params
,
String
pageId
)
{
bool
nativeContainerDidShow
(
String
name
,
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
FlutterBoost
.
containerManager
FlutterBoost
.
containerManager
?.
showContainer
(
_createContainerSettings
(
name
,
params
,
pageId
));
?.
showContainer
(
_createContainerSettings
(
name
,
params
,
pageId
));
//
在Android上对无障碍辅助模式的兼容
//
Compatible to accessibility mode on Android.
if
(
Platform
.
isAndroid
)
{
if
(
Platform
.
isAndroid
)
{
try
{
try
{
final
SemanticsOwner
owner
=
final
SemanticsOwner
owner
=
...
@@ -238,57 +221,93 @@ class ContainerCoordinator {
...
@@ -238,57 +221,93 @@ class ContainerCoordinator {
}
}
}
}
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
performContainerLifeCycle
(
ContainerLifeCycle
.
Appear
);
_createContainerSettings
(
name
,
params
,
pageId
),
ContainerLifeCycle
.
Appear
,
);
Logger
.
log
(
Logger
.
log
(
'native containner did show-
$name
,
\n
manager dump:
\n
${FlutterBoost.containerManager?.dump()}
'
);
'native containner did show-
$name
,
\n
'
'manager dump:
\n
'
'
${FlutterBoost.containerManager?.dump()}
'
,
);
return
true
;
return
true
;
}
}
bool
_nativeContainerWillDisappear
(
String
name
,
Map
params
,
String
pageId
)
{
bool
_nativeContainerWillDisappear
(
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
String
name
,
ContainerLifeCycle
.
WillDisappear
);
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
ContainerLifeCycle
.
WillDisappear
,
);
return
true
;
return
true
;
}
}
bool
_nativeContainerDidDisappear
(
String
name
,
Map
params
,
String
pageId
)
{
bool
_nativeContainerDidDisappear
(
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
String
name
,
ContainerLifeCycle
.
Disappear
);
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
ContainerLifeCycle
.
Disappear
,
);
return
true
;
return
true
;
}
}
bool
_nativeContainerDidInit
(
String
name
,
Map
params
,
String
pageId
)
{
bool
_nativeContainerDidInit
(
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
String
name
,
ContainerLifeCycle
.
Init
);
Map
<
String
,
dynamic
>
params
,
String
pageId
,
)
{
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
ContainerLifeCycle
.
Init
,
);
return
true
;
return
true
;
}
}
bool
_nativeContainerWillDealloc
(
String
name
,
Map
params
,
String
pageId
)
{
bool
_nativeContainerWillDealloc
(
String
name
,
Map
<
String
,
dynamic
>
params
,
String
pageId
)
{
try
{
try
{
performContainerLifeCycle
(
_createContainerSettings
(
name
,
params
,
pageId
),
performContainerLifeCycle
(
ContainerLifeCycle
.
Destroy
);
_createContainerSettings
(
name
,
params
,
pageId
),
ContainerLifeCycle
.
Destroy
,
);
}
catch
(
e
)
{
}
catch
(
e
)
{
Logger
.
log
(
'nativeContainerWillDealloc error:
$e
'
);
Logger
.
log
(
'nativeContainerWillDealloc error:
$e
'
);
}
}
FlutterBoost
.
containerManager
?.
remove
(
pageId
);
FlutterBoost
.
containerManager
?.
remove
(
pageId
);
Logger
.
log
(
Logger
.
log
(
'native containner dealloc for
$name
,
\n
manager dump:
\n
${FlutterBoost.containerManager?.dump()}
'
);
'native containner dealloc for
$name
,
\n
'
'manager dump:
\n
'
'
${FlutterBoost.containerManager?.dump()}
'
,
);
return
true
;
return
true
;
}
}
static
void
performContainerLifeCycle
(
static
void
performContainerLifeCycle
(
BoostContainerSettings
settings
,
ContainerLifeCycle
lifeCycle
)
{
BoostContainerSettings
settings
,
for
(
BoostContainerLifeCycleObserver
observer
in
FlutterBoost
ContainerLifeCycle
lifeCycle
,
)
{
final
Set
<
BoostContainerLifeCycleObserver
>
observers
=
FlutterBoost
.
singleton
.
observersHolder
.
singleton
.
observersHolder
.
observersOf
<
BoostContainerLifeCycleObserver
>())
{
.
observersOf
<
BoostContainerLifeCycleObserver
>();
for
(
final
BoostContainerLifeCycleObserver
observer
in
observers
)
{
observer
(
lifeCycle
,
settings
);
observer
(
lifeCycle
,
settings
);
}
}
Logger
.
log
(
Logger
.
log
(
'BoostContainerLifeCycleObserver container:
${settings.name}
lifeCycle:
$lifeCycle
'
);
'BoostContainerLifeCycleObserver'
'container:
${settings.name}
'
'lifeCycle:
$lifeCycle
'
,
);
}
}
}
}
lib/container/container_manager.dart
View file @
6f8de4fa
...
@@ -23,10 +23,11 @@
...
@@ -23,10 +23,11 @@
*/
*/
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'boost_container.dart'
;
import
'container_coordinator.dart'
;
import
'../flutter_boost.dart'
;
import
'../flutter_boost.dart'
;
import
'../support/logger.dart'
;
import
'../support/logger.dart'
;
import
'boost_container.dart'
;
import
'container_coordinator.dart'
;
enum
ContainerOperation
{
Push
,
Onstage
,
Pop
,
Remove
}
enum
ContainerOperation
{
Push
,
Onstage
,
Pop
,
Remove
}
...
@@ -35,12 +36,16 @@ typedef BoostContainerObserver = void Function(
...
@@ -35,12 +36,16 @@ typedef BoostContainerObserver = void Function(
@immutable
@immutable
class
BoostContainerManager
extends
StatefulWidget
{
class
BoostContainerManager
extends
StatefulWidget
{
const
BoostContainerManager
({
Key
key
,
this
.
initNavigator
,
this
.
prePushRoute
,
this
.
postPushRoute
,
})
:
super
(
key:
key
);
final
Navigator
initNavigator
;
final
Navigator
initNavigator
;
final
PrePushRoute
prePushRoute
;
final
PrePushRoute
prePushRoute
;
final
PostPushRoute
postPushRoute
;
final
PostPushRoute
postPushRoute
;
const
BoostContainerManager
(
{
Key
key
,
this
.
initNavigator
,
this
.
prePushRoute
,
this
.
postPushRoute
})
:
super
(
key:
key
);
@override
@override
ContainerManagerState
createState
()
=>
ContainerManagerState
();
ContainerManagerState
createState
()
=>
ContainerManagerState
();
...
@@ -76,15 +81,15 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -76,15 +81,15 @@ class ContainerManagerState extends State<BoostContainerManager> {
bool
get
foreground
=>
_foreground
;
bool
get
foreground
=>
_foreground
;
//Number of containers.
//
Number of containers.
int
get
containerCounts
=>
_offstage
.
length
;
int
get
containerCounts
=>
_offstage
.
length
;
List
<
BoostContainer
>
get
offstage
=>
_offstage
;
List
<
BoostContainer
>
get
offstage
=>
_offstage
;
//Setting for current visible container.
//
Setting for current visible container.
BoostContainerSettings
get
onstageSettings
=>
_onstage
.
settings
;
BoostContainerSettings
get
onstageSettings
=>
_onstage
.
settings
;
//Current visible container.
//
Current visible container.
BoostContainerState
get
onstageContainer
=>
_stateOf
(
_onstage
);
BoostContainerState
get
onstageContainer
=>
_stateOf
(
_onstage
);
BoostContainerState
get
subContainer
=>
BoostContainerState
get
subContainer
=>
...
@@ -118,8 +123,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -118,8 +123,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
}
}
BoostContainerState
_stateOf
(
BoostContainer
container
)
{
BoostContainerState
_stateOf
(
BoostContainer
container
)
{
if
(
container
.
key
!=
null
&&
if
(
container
.
key
is
GlobalKey
<
BoostContainerState
>)
{
container
.
key
is
GlobalKey
<
BoostContainerState
>)
{
final
GlobalKey
<
BoostContainerState
>
globalKey
=
final
GlobalKey
<
BoostContainerState
>
globalKey
=
container
.
key
as
GlobalKey
<
BoostContainerState
>;
container
.
key
as
GlobalKey
<
BoostContainerState
>;
return
globalKey
.
currentState
;
return
globalKey
.
currentState
;
...
@@ -133,7 +137,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -133,7 +137,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
void
_onShownContainerChanged
(
String
old
,
String
now
)
{
void
_onShownContainerChanged
(
String
old
,
String
now
)
{
Logger
.
log
(
'onShownContainerChanged old:
$old
now:
$now
'
);
Logger
.
log
(
'onShownContainerChanged old:
$old
now:
$now
'
);
Map
<
String
,
dynamic
>
properties
=
new
Map
<
String
,
dynamic
>()
;
final
Map
<
String
,
dynamic
>
properties
=
<
String
,
dynamic
>{}
;
properties
[
'newName'
]
=
now
;
properties
[
'newName'
]
=
now
;
properties
[
'oldName'
]
=
old
;
properties
[
'oldName'
]
=
old
;
...
@@ -149,7 +153,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -149,7 +153,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
}
}
if
(
_leastEntries
!=
null
&&
_leastEntries
.
isNotEmpty
)
{
if
(
_leastEntries
!=
null
&&
_leastEntries
.
isNotEmpty
)
{
for
(
_ContainerOverlayEntry
entry
in
_leastEntries
)
{
for
(
final
_ContainerOverlayEntry
entry
in
_leastEntries
)
{
entry
.
remove
();
entry
.
remove
();
}
}
}
}
...
@@ -223,7 +227,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -223,7 +227,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
setState
(()
{});
setState
(()
{});
for
(
BoostContainerObserver
observer
in
FlutterBoost
for
(
final
BoostContainerObserver
observer
in
FlutterBoost
.
singleton
.
observersHolder
.
singleton
.
observersHolder
.
observersOf
<
BoostContainerObserver
>())
{
.
observersOf
<
BoostContainerObserver
>())
{
observer
(
ContainerOperation
.
Onstage
,
_onstage
.
settings
);
observer
(
ContainerOperation
.
Onstage
,
_onstage
.
settings
);
...
@@ -265,7 +269,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -265,7 +269,7 @@ class ContainerManagerState extends State<BoostContainerManager> {
setState
(()
{});
setState
(()
{});
for
(
BoostContainerObserver
observer
in
FlutterBoost
for
(
final
BoostContainerObserver
observer
in
FlutterBoost
.
singleton
.
observersHolder
.
singleton
.
observersHolder
.
observersOf
<
BoostContainerObserver
>())
{
.
observersOf
<
BoostContainerObserver
>())
{
observer
(
ContainerOperation
.
Push
,
_onstage
.
settings
);
observer
(
ContainerOperation
.
Push
,
_onstage
.
settings
);
...
@@ -280,9 +284,11 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -280,9 +284,11 @@ class ContainerManagerState extends State<BoostContainerManager> {
_onstage
=
_offstage
.
removeLast
();
_onstage
=
_offstage
.
removeLast
();
setState
(()
{});
setState
(()
{});
f
or
(
BoostContainerObserver
observer
in
FlutterBoost
f
inal
Set
<
BoostContainerObserver
>
observers
=
FlutterBoost
.
singleton
.
observersHolder
.
singleton
.
observersHolder
.
observersOf
<
BoostContainerObserver
>())
{
.
observersOf
<
BoostContainerObserver
>();
for
(
final
BoostContainerObserver
observer
in
observers
)
{
observer
(
ContainerOperation
.
Pop
,
old
.
settings
);
observer
(
ContainerOperation
.
Pop
,
old
.
settings
);
}
}
...
@@ -295,31 +301,33 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -295,31 +301,33 @@ class ContainerManagerState extends State<BoostContainerManager> {
}
else
{
}
else
{
final
BoostContainer
container
=
_offstage
.
firstWhere
(
final
BoostContainer
container
=
_offstage
.
firstWhere
(
(
BoostContainer
container
)
=>
container
.
settings
.
uniqueId
==
uniqueId
,
(
BoostContainer
container
)
=>
container
.
settings
.
uniqueId
==
uniqueId
,
orElse:
()
=>
null
);
orElse:
()
=>
null
,
);
if
(
container
!=
null
)
{
if
(
container
!=
null
)
{
_offstage
.
remove
(
container
);
_offstage
.
remove
(
container
);
setState
(()
{});
setState
(()
{});
f
or
(
BoostContainerObserver
observer
in
FlutterBoost
f
inal
Set
<
BoostContainerObserver
>
observers
=
FlutterBoost
.
singleton
.
observersHolder
.
singleton
.
observersHolder
.
observersOf
<
BoostContainerObserver
>())
{
.
observersOf
<
BoostContainerObserver
>();
for
(
final
BoostContainerObserver
observer
in
observers
)
{
observer
(
ContainerOperation
.
Remove
,
container
.
settings
);
observer
(
ContainerOperation
.
Remove
,
container
.
settings
);
}
}
Logger
.
log
(
'ContainerObserver#2 didRemove'
);
Logger
.
log
(
'ContainerObserver#2 didRemove'
);
}
}
}
}
return
null
;
}
}
bool
canPop
()
=>
_offstage
.
isNotEmpty
;
bool
canPop
()
=>
_offstage
.
isNotEmpty
;
String
dump
()
{
String
dump
()
{
String
info
=
'onstage#:
\n
${_onstage?.desc()}
\n
offstage#:'
;
String
info
;
info
=
'onstage#:
\n
${_onstage?.desc()}
\n
offstage#:'
;
for
(
BoostContainer
container
in
_offstage
.
reversed
)
{
for
(
final
BoostContainer
container
in
_offstage
.
reversed
)
{
info
=
'
$info
\n
${container?.desc()}
'
;
info
=
'
$info
\n
${container?.desc()}
'
;
}
}
...
@@ -328,21 +336,21 @@ class ContainerManagerState extends State<BoostContainerManager> {
...
@@ -328,21 +336,21 @@ class ContainerManagerState extends State<BoostContainerManager> {
}
}
class
_ContainerOverlayEntry
extends
OverlayEntry
{
class
_ContainerOverlayEntry
extends
OverlayEntry
{
bool
_removed
=
false
;
_ContainerOverlayEntry
(
BoostContainer
container
)
_ContainerOverlayEntry
(
BoostContainer
container
)
:
super
(
:
super
(
builder:
(
BuildContext
ctx
)
=>
container
,
builder:
(
BuildContext
ctx
)
=>
container
,
opaque:
true
,
opaque:
true
,
maintainState:
true
);
maintainState:
true
,
);
bool
_removed
=
false
;
@override
@override
void
remove
()
{
void
remove
()
{
assert
(!
_removed
);
assert
(!
_removed
);
if
(
_removed
)
{
if
(
_removed
)
{
return
;
return
;
}
}
_removed
=
true
;
_removed
=
true
;
super
.
remove
();
super
.
remove
();
}
}
...
...
lib/flutter_boost.dart
View file @
6f8de4fa
...
@@ -25,58 +25,78 @@ import 'dart:async';
...
@@ -25,58 +25,78 @@ import 'dart:async';
import
'dart:io'
;
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'container/boost_container.dart'
;
import
'container/container_manager.dart'
;
import
'channel/boost_channel.dart'
;
import
'channel/boost_channel.dart'
;
import
'container/boost_container.dart'
;
import
'container/container_coordinator.dart'
;
import
'container/container_coordinator.dart'
;
import
'container/container_manager.dart'
;
import
'observers_holders.dart'
;
import
'observers_holders.dart'
;
export
'container/boost_container.dart'
;
export
'container/boost_container.dart'
;
export
'container/container_manager.dart'
;
export
'container/container_manager.dart'
;
typedef
Widget
PageBuilder
(
String
pageName
,
Map
params
,
String
uniqueId
);
typedef
PageBuilder
=
Widget
Function
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
uniqueId
);
typedef
Route
PrePushRoute
(
typedef
PrePushRoute
=
Route
<
T
>
Function
<
T
>(
String
url
,
String
uniqueId
,
String
url
,
String
uniqueId
,
Map
params
,
Route
route
);
Map
<
String
,
dynamic
>
params
,
Route
<
dynamic
>
route
);
typedef
void
PostPushRoute
(
typedef
PostPushRoute
=
void
Function
(
String
url
,
String
uniqueId
,
Map
params
,
Route
route
,
Future
result
);
String
url
,
String
uniqueId
,
Map
<
String
,
dynamic
>
params
,
Route
<
dynamic
>
route
,
Future
<
dynamic
>
result
,
);
class
FlutterBoost
{
class
FlutterBoost
{
FlutterBoost
()
{
ContainerCoordinator
(
_boostChannel
);
}
static
final
FlutterBoost
_instance
=
FlutterBoost
();
static
final
FlutterBoost
_instance
=
FlutterBoost
();
final
GlobalKey
<
ContainerManagerState
>
containerManagerKey
=
GlobalKey
<
ContainerManagerState
>();
final
ObserversHolder
_observersHolder
=
ObserversHolder
();
final
BoostChannel
_boostChannel
=
BoostChannel
();
static
FlutterBoost
get
singleton
=>
_instance
;
static
FlutterBoost
get
singleton
=>
_instance
;
static
ContainerManagerState
get
containerManager
=>
static
ContainerManagerState
get
containerManager
=>
_instance
.
containerManagerKey
.
currentState
;
_instance
.
containerManagerKey
.
currentState
;
static
void
onPageStart
()
{
final
GlobalKey
<
ContainerManagerState
>
containerManagerKey
=
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
GlobalKey
<
ContainerManagerState
>();
singleton
.
channel
.
invokeMethod
<
Map
>(
'pageOnStart'
).
then
((
Map
pageInfo
)
{
final
ObserversHolder
_observersHolder
=
ObserversHolder
();
if
(
pageInfo
==
null
||
pageInfo
.
isEmpty
)
return
;
final
BoostChannel
_boostChannel
=
BoostChannel
()
;
if
(
pageInfo
.
containsKey
(
"name"
)
&&
static
void
onPageStart
()
{
pageInfo
.
containsKey
(
"params"
)
&&
WidgetsBinding
.
instance
.
addPostFrameCallback
((
Duration
_
)
{
pageInfo
.
containsKey
(
"uniqueId"
))
{
singleton
.
channel
.
invokeMethod
<
Map
<
String
,
dynamic
>>(
'pageOnStart'
)
.
then
((
Map
<
String
,
dynamic
>
pageInfo
)
{
if
(
pageInfo
?.
isEmpty
??
true
)
{
return
;
}
if
(
pageInfo
.
containsKey
(
'name'
)
&&
pageInfo
.
containsKey
(
'params'
)
&&
pageInfo
.
containsKey
(
'uniqueId'
))
{
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
pageInfo
[
"name"
],
pageInfo
[
"params"
],
pageInfo
[
"uniqueId"
]);
pageInfo
[
'name'
]
as
String
,
(
pageInfo
[
'params'
]
as
Map
<
dynamic
,
dynamic
>)
?.
cast
<
String
,
dynamic
>(),
pageInfo
[
'uniqueId'
]
as
String
,
);
}
}
});
});
});
});
}
}
static
TransitionBuilder
init
(
static
TransitionBuilder
init
(
{
{
TransitionBuilder
builder
,
TransitionBuilder
builder
,
PrePushRoute
prePush
,
PrePushRoute
prePush
,
PostPushRoute
postPush
})
{
PostPushRoute
postPush
,
})
{
if
(
Platform
.
isAndroid
)
{
if
(
Platform
.
isAndroid
)
{
onPageStart
();
onPageStart
();
}
else
if
(
Platform
.
isIOS
)
{
}
else
if
(
Platform
.
isIOS
)
{
// TODO(AlexVincent525): 未解之谜
assert
(()
{
assert
(()
{
()
async
{
()
async
{
onPageStart
();
onPageStart
();
...
@@ -90,9 +110,10 @@ class FlutterBoost {
...
@@ -90,9 +110,10 @@ class FlutterBoost {
final
BoostContainerManager
manager
=
BoostContainerManager
(
final
BoostContainerManager
manager
=
BoostContainerManager
(
key:
_instance
.
containerManagerKey
,
key:
_instance
.
containerManagerKey
,
initNavigator:
child
,
initNavigator:
child
as
Navigator
,
prePushRoute:
prePush
,
prePushRoute:
prePush
,
postPushRoute:
postPush
);
postPushRoute:
postPush
,
);
if
(
builder
!=
null
)
{
if
(
builder
!=
null
)
{
return
builder
(
context
,
manager
);
return
builder
(
context
,
manager
);
...
@@ -106,94 +127,95 @@ class FlutterBoost {
...
@@ -106,94 +127,95 @@ class FlutterBoost {
BoostChannel
get
channel
=>
_boostChannel
;
BoostChannel
get
channel
=>
_boostChannel
;
FlutterBoost
()
{
/// Register a default page builder.
ContainerCoordinator
(
_boostChannel
);
}
///Register a default page builder.
void
registerDefaultPageBuilder
(
PageBuilder
builder
)
{
void
registerDefaultPageBuilder
(
PageBuilder
builder
)
{
ContainerCoordinator
.
singleton
.
registerDefaultPageBuilder
(
builder
);
ContainerCoordinator
.
singleton
.
registerDefaultPageBuilder
(
builder
);
}
}
///Register a map builders
///
Register a map builders
void
registerPageBuilders
(
Map
<
String
,
PageBuilder
>
builders
)
{
void
registerPageBuilders
(
Map
<
String
,
PageBuilder
>
builders
)
{
ContainerCoordinator
.
singleton
.
registerPageBuilders
(
builders
);
ContainerCoordinator
.
singleton
.
registerPageBuilders
(
builders
);
}
}
Future
<
Map
<
dynamic
,
dynamic
>>
open
(
String
url
,
Future
<
Map
<
String
,
dynamic
>>
open
(
{
Map
<
dynamic
,
dynamic
>
urlParams
,
Map
<
dynamic
,
dynamic
>
exts
})
{
String
url
,
{
Map
<
dynamic
,
dynamic
>
properties
=
new
Map
<
dynamic
,
dynamic
>();
Map
<
String
,
dynamic
>
urlParams
,
properties
[
"url"
]
=
url
;
Map
<
String
,
dynamic
>
exts
,
properties
[
"urlParams"
]
=
urlParams
;
})
{
properties
[
"exts"
]
=
exts
;
final
Map
<
String
,
dynamic
>
properties
=
<
String
,
dynamic
>{};
return
channel
.
invokeMethod
<
Map
<
dynamic
,
dynamic
>>(
'openPage'
,
properties
);
properties
[
'url'
]
=
url
;
properties
[
'urlParams'
]
=
urlParams
;
properties
[
'exts'
]
=
exts
;
return
channel
.
invokeMethod
<
Map
<
String
,
dynamic
>>(
'openPage'
,
properties
);
}
}
Future
<
bool
>
close
(
String
id
,
Future
<
bool
>
close
(
{
Map
<
dynamic
,
dynamic
>
result
,
Map
<
dynamic
,
dynamic
>
exts
})
{
String
id
,
{
Map
<
String
,
dynamic
>
result
,
Map
<
String
,
dynamic
>
exts
,
})
{
assert
(
id
!=
null
);
assert
(
id
!=
null
);
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
final
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
Map
<
dynamic
,
dynamic
>
properties
=
new
Map
<
dynamic
,
dynamic
>()
;
final
Map
<
String
,
dynamic
>
properties
=
<
String
,
dynamic
>{}
;
if
(
exts
==
null
)
{
exts
??=
<
String
,
dynamic
>{};
exts
=
Map
<
dynamic
,
dynamic
>();
}
exts
[
"params"
]
=
settings
.
params
;
exts
[
'params'
]
=
settings
.
params
;
if
(!
exts
.
containsKey
(
"animated"
))
{
if
(!
exts
.
containsKey
(
'animated'
))
{
exts
[
"animated"
]
=
true
;
exts
[
'animated'
]
=
true
;
}
}
properties
[
"uniqueId"
]
=
id
;
properties
[
'uniqueId'
]
=
id
;
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
properties
[
"result"
]
=
result
;
properties
[
'result'
]
=
result
;
}
}
if
(
exts
!=
null
)
{
if
(
exts
!=
null
)
{
properties
[
"exts"
]
=
exts
;
properties
[
'exts'
]
=
exts
;
}
}
return
channel
.
invokeMethod
<
bool
>(
'closePage'
,
properties
);
return
channel
.
invokeMethod
<
bool
>(
'closePage'
,
properties
);
}
}
Future
<
bool
>
closeCurrent
(
Future
<
bool
>
closeCurrent
(
{
{
Map
<
String
,
dynamic
>
result
,
Map
<
String
,
dynamic
>
exts
})
{
Map
<
String
,
dynamic
>
result
,
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
Map
<
String
,
dynamic
>
exts
,
if
(
exts
==
null
)
{
}
)
{
exts
=
Map
<
String
,
dynamic
>()
;
final
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
}
exts
??=
<
String
,
dynamic
>{};
exts
[
"params"
]
=
settings
.
params
;
exts
[
'params'
]
=
settings
.
params
;
if
(!
exts
.
containsKey
(
"animated"
))
{
if
(!
exts
.
containsKey
(
'animated'
))
{
exts
[
"animated"
]
=
true
;
exts
[
'animated'
]
=
true
;
}
}
return
close
(
settings
.
uniqueId
,
result:
result
,
exts:
exts
);
return
close
(
settings
.
uniqueId
,
result:
result
,
exts:
exts
);
}
}
Future
<
bool
>
closeByContext
(
BuildContext
context
,
Future
<
bool
>
closeByContext
(
{
Map
<
String
,
dynamic
>
result
,
Map
<
String
,
dynamic
>
exts
})
{
BuildContext
context
,
{
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
Map
<
String
,
dynamic
>
result
,
if
(
exts
==
null
)
{
Map
<
String
,
dynamic
>
exts
,
exts
=
Map
<
String
,
dynamic
>();
})
{
}
final
BoostContainerSettings
settings
=
containerManager
?.
onstageSettings
;
exts
[
"params"
]
=
settings
.
params
;
exts
??=
<
String
,
dynamic
>{};
if
(!
exts
.
containsKey
(
"animated"
))
{
exts
[
'params'
]
=
settings
.
params
;
exts
[
"animated"
]
=
true
;
if
(!
exts
.
containsKey
(
'animated'
))
{
exts
[
'animated'
]
=
true
;
}
}
return
close
(
settings
.
uniqueId
,
result:
result
,
exts:
exts
);
return
close
(
settings
.
uniqueId
,
result:
result
,
exts:
exts
);
}
}
///
r
egister for Container changed callbacks
///
R
egister for Container changed callbacks
VoidCallback
addContainerObserver
(
BoostContainerObserver
observer
)
=>
VoidCallback
addContainerObserver
(
BoostContainerObserver
observer
)
=>
_observersHolder
.
addObserver
<
BoostContainerObserver
>(
observer
);
_observersHolder
.
addObserver
<
BoostContainerObserver
>(
observer
);
///
r
egister for Container lifecycle callbacks
///
R
egister for Container lifecycle callbacks
VoidCallback
addBoostContainerLifeCycleObserver
(
VoidCallback
addBoostContainerLifeCycleObserver
(
BoostContainerLifeCycleObserver
observer
)
=>
BoostContainerLifeCycleObserver
observer
)
=>
_observersHolder
.
addObserver
<
BoostContainerLifeCycleObserver
>(
observer
);
_observersHolder
.
addObserver
<
BoostContainerLifeCycleObserver
>(
observer
);
///
register callbacks for Navigators push & pop
///
Register callbacks for [Navigator.push] & [Navigator.pop]
void
addBoostNavigatorObserver
(
NavigatorObserver
observer
)
=>
void
addBoostNavigatorObserver
(
NavigatorObserver
observer
)
=>
ContainerNavigatorObserver
.
boostObservers
.
add
(
observer
);
ContainerNavigatorObserver
.
boostObservers
.
add
(
observer
);
}
}
lib/observers_holders.dart
View file @
6f8de4fa
...
@@ -24,10 +24,10 @@
...
@@ -24,10 +24,10 @@
import
'dart:ui'
;
import
'dart:ui'
;
class
ObserversHolder
{
class
ObserversHolder
{
final
Map
<
String
,
Set
<
dynamic
>>
_observers
=
Map
<
String
,
Set
<
dynamic
>>()
;
final
Map
<
String
,
Set
<
dynamic
>>
_observers
=
<
String
,
Set
<
dynamic
>>{}
;
VoidCallback
addObserver
<
T
>(
T
observer
)
{
VoidCallback
addObserver
<
T
>(
T
observer
)
{
final
Set
<
T
>
set
=
_observers
[
T
.
toString
()]
??
Set
<
T
>()
;
final
Set
<
T
>
set
=
_observers
[
T
.
toString
()]
as
Set
<
T
>
??
<
T
>{}
;
set
.
add
(
observer
);
set
.
add
(
observer
);
_observers
[
T
.
toString
()]
=
set
;
_observers
[
T
.
toString
()]
=
set
;
...
@@ -40,5 +40,5 @@ class ObserversHolder {
...
@@ -40,5 +40,5 @@ class ObserversHolder {
void
cleanObservers
<
T
>(
T
observer
)
=>
_observers
[
T
.
toString
()]?.
clear
();
void
cleanObservers
<
T
>(
T
observer
)
=>
_observers
[
T
.
toString
()]?.
clear
();
Set
<
T
>
observersOf
<
T
>()
=>
_observers
[
T
.
toString
()]
??
Set
<
T
>()
;
Set
<
T
>
observersOf
<
T
>()
=>
_observers
[
T
.
toString
()]
as
Set
<
T
>
??
<
T
>{}
;
}
}
lib/support/logger.dart
View file @
6f8de4fa
...
@@ -27,7 +27,6 @@ class Logger {
...
@@ -27,7 +27,6 @@ class Logger {
print
(
'FlutterBoost#
$msg
'
);
print
(
'FlutterBoost#
$msg
'
);
return
true
;
return
true
;
}());
}());
//print('FlutterBoost=>$msg');
}
}
static
void
error
(
String
msg
)
{
static
void
error
(
String
msg
)
{
...
...
pubspec.yaml
View file @
6f8de4fa
...
@@ -17,42 +17,7 @@ dev_dependencies:
...
@@ -17,42 +17,7 @@ dev_dependencies:
sdk
:
flutter
sdk
:
flutter
mockito
:
4.1.1
mockito
:
4.1.1
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter
:
flutter
:
plugin
:
plugin
:
androidPackage
:
com.idlefish.flutterboost
androidPackage
:
com.idlefish.flutterboost
pluginClass
:
FlutterBoostPlugin
pluginClass
:
FlutterBoostPlugin
# To add assets to your plugin package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your plugin package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
test/lib/unit/boost_channel_test.dart
View file @
6f8de4fa
import
'package:flutter
_boost/channel/boost_channel
.dart'
;
import
'package:flutter
/foundation
.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_boost/channel/boost_channel.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
void
main
(
)
{
...
@@ -22,13 +23,12 @@ void main() {
...
@@ -22,13 +23,12 @@ void main() {
response
=
null
;
response
=
null
;
test
(
'sendEvent successfully'
,
()
async
{
test
(
'sendEvent successfully'
,
()
async
{
Map
msg1
=
Map
<
dynamic
,
dynamic
>();
final
Map
<
String
,
dynamic
>
msg1
=
<
String
,
dynamic
>{};
BoostChannel
().
sendEvent
(
"name"
,
msg1
);
BoostChannel
().
sendEvent
(
'name'
,
msg1
);
Map
msg
=
Map
<
dynamic
,
dynamic
>();
msg
[
"name"
]
=
"name"
;
msg
[
"arguments"
]
=
msg1
;
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{};
msg
[
'name'
]
=
'name'
;
msg
[
'arguments'
]
=
msg1
;
expect
(
expect
(
log
,
log
,
...
@@ -36,13 +36,10 @@ void main() {
...
@@ -36,13 +36,10 @@ void main() {
);
);
});
});
test
(
'invokeMethod successfully'
,
()
async
{
test
(
'invokeMethod successfully'
,
()
async
{
Map
msg
=
<
dynamic
,
dynamic
>{};
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{};
msg
[
"test"
]
=
"test"
;
msg
[
'test'
]
=
'test'
;
BoostChannel
().
invokeMethod
<
dynamic
>(
"__event__1"
,
msg
);
BoostChannel
().
invokeMethod
<
dynamic
>(
'__event__1'
,
msg
);
// expect(e, isException);
expect
(
expect
(
log
,
log
,
...
@@ -50,11 +47,10 @@ void main() {
...
@@ -50,11 +47,10 @@ void main() {
);
);
});
});
test
(
'invokeListMethod successfully'
,
()
async
{
test
(
'invokeListMethod successfully'
,
()
async
{
Map
msg
=
<
dynamic
,
dynamic
>{};
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{};
msg
[
"test"
]
=
"test"
;
msg
[
'test'
]
=
'test'
;
var
bb
=
await
BoostChannel
().
invokeListMethod
<
dynamic
>(
"__event__1"
,
msg
);
await
BoostChannel
().
invokeListMethod
<
dynamic
>(
'__event__1'
,
msg
);
expect
(
expect
(
log
,
log
,
...
@@ -62,11 +58,10 @@ void main() {
...
@@ -62,11 +58,10 @@ void main() {
);
);
});
});
test
(
'invokeMapMethod successfully'
,
()
async
{
test
(
'invokeMapMethod successfully'
,
()
async
{
Map
msg
=
<
dynamic
,
dynamic
>{};
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{};
msg
[
"test"
]
=
"test"
;
msg
[
'test'
]
=
'test'
;
BoostChannel
().
invokeMapMethod
<
dynamic
,
dynamic
>(
"__event__1"
,
msg
);
BoostChannel
().
invokeMapMethod
<
dynamic
,
dynamic
>(
'__event__1'
,
msg
);
expect
(
expect
(
log
,
log
,
...
@@ -75,9 +70,9 @@ void main() {
...
@@ -75,9 +70,9 @@ void main() {
});
});
test
(
'invokeMapMethod successfully'
,
()
async
{
test
(
'invokeMapMethod successfully'
,
()
async
{
Map
msg
=
<
dynamic
,
dynamic
>{};
final
Map
<
String
,
dynamic
>
msg
=
<
String
,
dynamic
>{};
msg
[
"test"
]
=
"test"
;
msg
[
'test'
]
=
'test'
;
BoostChannel
().
invokeMapMethod
<
dynamic
,
dynamic
>(
"__event__1"
,
msg
);
BoostChannel
().
invokeMapMethod
<
dynamic
,
dynamic
>(
'__event__1'
,
msg
);
expect
(
expect
(
log
,
log
,
...
@@ -86,22 +81,24 @@ void main() {
...
@@ -86,22 +81,24 @@ void main() {
});
});
test
(
'addEventListener successfully'
,
()
async
{
test
(
'addEventListener successfully'
,
()
async
{
Function
test
=
BoostChannel
().
addEventListener
(
final
VoidCallback
test
=
BoostChannel
().
addEventListener
(
"addEventListener"
,
(
String
name
,
Map
arguments
)
async
=>
"test"
);
'addEventListener'
,
print
(
"xxx"
+
test
.
toString
());
(
String
name
,
Map
<
String
,
dynamic
>
arguments
)
async
=>
'test'
,
);
print
(
'xxx'
+
test
.
toString
());
expect
(
expect
(
test
.
toString
(),
test
.
toString
(),
"Closure: () => Null"
,
'Closure: () => Null'
,
);
);
});
});
test
(
'addMethodHandler successfully'
,
()
async
{
test
(
'addMethodHandler successfully'
,
()
async
{
Function
test
=
BoostChannel
().
addMethodHandler
((
final
VoidCallback
test
=
BoostChannel
().
addMethodHandler
(
MethodCall
call
)
async
=>
"test"
);
(
MethodCall
call
)
async
=>
'test'
,
);
expect
(
expect
(
test
.
toString
(),
test
.
toString
(),
"Closure: () => Null"
,
'Closure: () => Null'
,
);
);
});
});
});
});
...
...
test/lib/unit/boost_container_test.dart
View file @
6f8de4fa
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_boost/container/boost_container.dart'
;
//
import 'package:flutter_boost/container/boost_container.dart';
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
class
FirstWidget
extends
StatelessWidget
{
class
FirstWidget
extends
StatelessWidget
{
...
@@ -149,11 +149,11 @@ void main() {
...
@@ -149,11 +149,11 @@ void main() {
);
);
await
tester
.
pumpWidget
(
widget
);
await
tester
.
pumpWidget
(
widget
);
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
tap
(
find
.
byKey
(
targetKey
));
await
tester
.
tap
(
find
.
byKey
(
targetKey
));
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
exception
,
isInstanceOf
<
FlutterError
>());
expect
(
exception
,
isInstanceOf
<
FlutterError
>());
expect
(
'
$exception
'
,
expect
(
'
$exception
'
,
...
...
test/lib/unit/boost_page_route_test.dart
View file @
6f8de4fa
...
@@ -49,8 +49,8 @@ void main() {
...
@@ -49,8 +49,8 @@ void main() {
testWidgets
(
testWidgets
(
'obtain BoostPageRoute through the BoostPageRoute.of(context) method'
,
'obtain BoostPageRoute through the BoostPageRoute.of(context) method'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
dynamic
boostPageRoute
;
BoostPageRoute
<
dynamic
>
boostPageRoute
;
dynamic
boostPageRouteFindByOfMethod
;
BoostPageRoute
<
dynamic
>
boostPageRouteFindByOfMethod
;
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -58,10 +58,11 @@ void main() {
...
@@ -58,10 +58,11 @@ void main() {
boostPageRoute
=
BoostPageRoute
<
void
>(
boostPageRoute
=
BoostPageRoute
<
void
>(
settings:
settings
,
settings:
settings
,
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
context
)
{
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
boostPageRouteFindByOfMethod
=
BoostPageRoute
.
of
<
dynamic
>(
context
);
boostPageRouteFindByOfMethod
=
BoostPageRoute
.
of
<
dynamic
>(
context
);
},
},
);
);
},
},
...
@@ -74,7 +75,7 @@ void main() {
...
@@ -74,7 +75,7 @@ void main() {
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// The route obtained from the ancestor node through the `of` method should be the same BoostPageRoute
// The route obtained from the ancestor node through the `of` method should be the same BoostPageRoute
// as the originally created BoostPageRoute
// as the originally created BoostPageRoute
...
@@ -85,15 +86,15 @@ void main() {
...
@@ -85,15 +86,15 @@ void main() {
'try to find BoostPageRoute through the BoostPageRoute.of(context) method, '
'try to find BoostPageRoute through the BoostPageRoute.of(context) method, '
'but it doesn
\'
t exist, the method should throw an Exception'
,
'but it doesn
\'
t exist, the method should throw an Exception'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
dynamic
contextCache
;
BuildContext
contextCache
;
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
onGenerateRoute:
(
RouteSettings
settings
)
{
onGenerateRoute:
(
RouteSettings
settings
)
{
return
MaterialPageRoute
<
dynamic
>(
return
MaterialPageRoute
<
dynamic
>(
settings:
settings
,
settings:
settings
,
builder:
(
context
)
=>
Builder
(
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
context
)
=>
FloatingActionButton
(
builder:
(
BuildContext
context
)
=>
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
contextCache
=
context
;
contextCache
=
context
;
},
},
...
@@ -104,7 +105,7 @@ void main() {
...
@@ -104,7 +105,7 @@ void main() {
),
),
);
);
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(()
=>
BoostPageRoute
.
of
<
dynamic
>(
contextCache
),
throwsException
);
expect
(()
=>
BoostPageRoute
.
of
<
dynamic
>(
contextCache
),
throwsException
);
});
});
...
@@ -112,8 +113,8 @@ void main() {
...
@@ -112,8 +113,8 @@ void main() {
testWidgets
(
testWidgets
(
'obtain BoostPageRoute through the BoostPageRoute.tryOf(context) method'
,
'obtain BoostPageRoute through the BoostPageRoute.tryOf(context) method'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
dynamic
boostPageRoute
;
BoostPageRoute
<
dynamic
>
boostPageRoute
;
dynamic
boostPageRouteFindByOfMethod
;
BoostPageRoute
<
dynamic
>
boostPageRouteFindByOfMethod
;
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -121,7 +122,7 @@ void main() {
...
@@ -121,7 +122,7 @@ void main() {
boostPageRoute
=
BoostPageRoute
<
void
>(
boostPageRoute
=
BoostPageRoute
<
void
>(
settings:
settings
,
settings:
settings
,
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
context
)
{
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
boostPageRouteFindByOfMethod
=
boostPageRouteFindByOfMethod
=
...
@@ -137,7 +138,7 @@ void main() {
...
@@ -137,7 +138,7 @@ void main() {
);
);
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// The route obtained from the ancestor node through the `tryOf` method should be the same BoostPageRoute
// The route obtained from the ancestor node through the `tryOf` method should be the same BoostPageRoute
// as the originally created BoostPageRoute
// as the originally created BoostPageRoute
...
@@ -149,7 +150,7 @@ void main() {
...
@@ -149,7 +150,7 @@ void main() {
'try to find BoostPageRoute through the BoostPageRoute.tryOf(context) method, '
'try to find BoostPageRoute through the BoostPageRoute.tryOf(context) method, '
'but it doesn
\'
t exist, the method should return null'
,
'but it doesn
\'
t exist, the method should return null'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
dynamic
boostPageRouteFindByOfMethod
;
BoostPageRoute
<
dynamic
>
boostPageRouteFindByOfMethod
;
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -157,7 +158,7 @@ void main() {
...
@@ -157,7 +158,7 @@ void main() {
return
MaterialPageRoute
<
dynamic
>(
return
MaterialPageRoute
<
dynamic
>(
settings:
settings
,
settings:
settings
,
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
BuildContext
context
)
=>
Builder
(
builder:
(
context
)
{
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
boostPageRouteFindByOfMethod
=
boostPageRouteFindByOfMethod
=
...
@@ -172,7 +173,7 @@ void main() {
...
@@ -172,7 +173,7 @@ void main() {
);
);
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
boostPageRouteFindByOfMethod
,
null
);
expect
(
boostPageRouteFindByOfMethod
,
null
);
});
});
...
...
test/lib/unit/container_coordinator_test.dart
View file @
6f8de4fa
...
@@ -6,9 +6,6 @@ import 'package:flutter_test/flutter_test.dart';
...
@@ -6,9 +6,6 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:mockito/mockito.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:flutter_boost/channel/boost_channel.dart'
;
import
'package:flutter_boost/channel/boost_channel.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'dart:typed_data'
;
class
MockBoostChannel
extends
BoostChannel
implements
Mock
{
class
MockBoostChannel
extends
BoostChannel
implements
Mock
{
MethodHandler
get
testHandler
=>
_testHandler
;
MethodHandler
get
testHandler
=>
_testHandler
;
...
@@ -17,12 +14,14 @@ class MockBoostChannel extends BoostChannel implements Mock {
...
@@ -17,12 +14,14 @@ class MockBoostChannel extends BoostChannel implements Mock {
MethodHandler
_testHandler
;
MethodHandler
_testHandler
;
EventListener
_testEventListener
;
EventListener
_testEventListener
;
@override
VoidCallback
addEventListener
(
String
name
,
EventListener
listener
)
{
VoidCallback
addEventListener
(
String
name
,
EventListener
listener
)
{
_testEventListener
=
listener
;
_testEventListener
=
listener
;
return
super
.
addEventListener
(
name
,
listener
);
return
super
.
addEventListener
(
name
,
listener
);
}
}
@override
VoidCallback
addMethodHandler
(
MethodHandler
handler
)
{
VoidCallback
addMethodHandler
(
MethodHandler
handler
)
{
_testHandler
=
handler
;
_testHandler
=
handler
;
return
super
.
addMethodHandler
(
handler
);
return
super
.
addMethodHandler
(
handler
);
...
@@ -31,26 +30,26 @@ class MockBoostChannel extends BoostChannel implements Mock {
...
@@ -31,26 +30,26 @@ class MockBoostChannel extends BoostChannel implements Mock {
void
main
(
)
{
void
main
(
)
{
TestWidgetsFlutterBinding
.
ensureInitialized
();
TestWidgetsFlutterBinding
.
ensureInitialized
();
const
MessageCodec
<
dynamic
>
jsonMessage
=
JSONMessageCodec
();
//
const MessageCodec<dynamic> jsonMessage = JSONMessageCodec();
test
(
'test onMethodCall'
,
()
async
{
test
(
'test onMethodCall'
,
()
async
{
// Initialize all bindings because defaultBinaryMessenger.send() needs a window.
// Initialize all bindings because defaultBinaryMessenger.send() needs a window.
TestWidgetsFlutterBinding
.
ensureInitialized
();
TestWidgetsFlutterBinding
.
ensureInitialized
();
MockBoostChannel
boostChannel
=
MockBoostChannel
();
final
MockBoostChannel
boostChannel
=
MockBoostChannel
();
ContainerCoordinator
(
boostChannel
);
ContainerCoordinator
(
boostChannel
);
final
Map
arguments
=<
dynamic
,
dynamic
>
{};
final
Map
<
String
,
dynamic
>
arguments
=
<
String
,
dynamic
>
{};
arguments
[
"pageName"
]
=
"pageName"
;
arguments
[
'pageName'
]
=
'pageName'
;
arguments
[
"params"
]
=
<
dynamic
,
dynamic
>{};
arguments
[
'params'
]
=
<
dynamic
,
dynamic
>{};
arguments
[
"uniqueId"
]
=
"xxxxx"
;
arguments
[
'uniqueId'
]
=
'xxxxx'
;
MethodCall
call
=
MethodCall
(
'didInitPageContainer'
,
arguments
);
final
MethodCall
call
=
MethodCall
(
'didInitPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call
);
boostChannel
.
testHandler
(
call
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isAssertionError
);
expect
(
e
,
isAssertionError
);
}
}
MethodCall
call2
=
MethodCall
(
'willShowPageContainer'
,
arguments
);
final
MethodCall
call2
=
MethodCall
(
'willShowPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call2
);
boostChannel
.
testHandler
(
call2
);
...
@@ -58,7 +57,7 @@ void main() {
...
@@ -58,7 +57,7 @@ void main() {
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
MethodCall
call3
=
MethodCall
(
'didShowPageContainer'
,
arguments
);
final
MethodCall
call3
=
MethodCall
(
'didShowPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call3
);
boostChannel
.
testHandler
(
call3
);
...
@@ -66,7 +65,8 @@ void main() {
...
@@ -66,7 +65,8 @@ void main() {
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
MethodCall
call4
=
MethodCall
(
'willDisappearPageContainer'
,
arguments
);
final
MethodCall
call4
=
MethodCall
(
'willDisappearPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call4
);
boostChannel
.
testHandler
(
call4
);
...
@@ -74,7 +74,7 @@ void main() {
...
@@ -74,7 +74,7 @@ void main() {
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
MethodCall
call5
=
MethodCall
(
'onNativePageResult'
,
arguments
);
final
MethodCall
call5
=
MethodCall
(
'onNativePageResult'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call5
);
boostChannel
.
testHandler
(
call5
);
...
@@ -82,14 +82,14 @@ void main() {
...
@@ -82,14 +82,14 @@ void main() {
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
MethodCall
call6
=
MethodCall
(
'didDisappearPageContainer'
,
arguments
);
final
MethodCall
call6
=
MethodCall
(
'didDisappearPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call6
);
boostChannel
.
testHandler
(
call6
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
MethodCall
call7
=
MethodCall
(
'willDeallocPageContainer'
,
arguments
);
final
MethodCall
call7
=
MethodCall
(
'willDeallocPageContainer'
,
arguments
);
try
{
try
{
boostChannel
.
testHandler
(
call7
);
boostChannel
.
testHandler
(
call7
);
...
@@ -97,35 +97,36 @@ void main() {
...
@@ -97,35 +97,36 @@ void main() {
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
Map
arg
=
<
dynamic
,
dynamic
>{
'type'
:
'backPressedCallback'
};
final
Map
<
String
,
dynamic
>
arg
=
<
String
,
dynamic
>{
'type'
:
'backPressedCallback'
};
try
{
try
{
boostChannel
.
testEventListener
(
"lifecycle"
,
arg
);
boostChannel
.
testEventListener
(
'lifecycle'
,
arg
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
final
Map
<
String
,
dynamic
>
arg2
=
<
String
,
dynamic
>{
'type'
:
'foreground'
};
Map
arg2
=
<
dynamic
,
dynamic
>{
'type'
:
'foreground'
};
try
{
try
{
boostChannel
.
testEventListener
(
"lifecycle"
,
arg2
);
boostChannel
.
testEventListener
(
'lifecycle'
,
arg2
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
Map
arg3
=
<
dynamic
,
dynamic
>{
'type'
:
'background'
};
final
Map
<
String
,
dynamic
>
arg3
=
<
String
,
dynamic
>{
'type'
:
'background'
};
try
{
try
{
boostChannel
.
testEventListener
(
"lifecycle"
,
arg3
);
boostChannel
.
testEventListener
(
'lifecycle'
,
arg3
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
Map
arg4
=
<
dynamic
,
dynamic
>{
'type'
:
'scheduleFrame'
};
final
Map
<
String
,
dynamic
>
arg4
=
<
String
,
dynamic
>{
'type'
:
'scheduleFrame'
};
try
{
try
{
boostChannel
.
testEventListener
(
"lifecycle"
,
arg4
);
boostChannel
.
testEventListener
(
'lifecycle'
,
arg4
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
expect
(
e
,
isNoSuchMethodError
);
}
}
});
});
}
}
test/lib/unit/container_manager_test.dart
View file @
6f8de4fa
...
@@ -12,19 +12,21 @@ class FirstRouteWidget extends StatelessWidget {
...
@@ -12,19 +12,21 @@ class FirstRouteWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
'First Route'
),
title:
const
Text
(
'First Route'
),
),
),
body:
Center
(
body:
Center
(
child:
Column
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
children:
<
Widget
>[
RaisedButton
(
RaisedButton
(
child:
Text
(
'First'
),
child:
const
Text
(
'First'
),
onPressed:
()
{
onPressed:
()
{
print
(
"open second page!"
);
print
(
'open second page!'
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
FlutterBoost
.
singleton
.
open
(
'second'
)
.
then
((
Map
<
String
,
dynamic
>
value
)
{
print
(
print
(
"call me when page is finished. did recieve second route result
$value
"
);
'call me when page is finished. did recieve second route result
$value
'
);
});
});
},
},
),
),
...
@@ -40,19 +42,21 @@ class SecondRouteWidget extends StatelessWidget {
...
@@ -40,19 +42,21 @@ class SecondRouteWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
'Second Route'
),
title:
const
Text
(
'Second Route'
),
),
),
body:
Center
(
body:
Center
(
child:
Column
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
children:
<
Widget
>[
RaisedButton
(
RaisedButton
(
child:
Text
(
'Second'
),
child:
const
Text
(
'Second'
),
onPressed:
()
{
onPressed:
()
{
print
(
"open second page!"
);
print
(
'open second page!'
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
FlutterBoost
.
singleton
.
open
(
'second'
)
.
then
((
Map
<
String
,
dynamic
>
value
)
{
print
(
print
(
"call me when page is finished. did recieve second route result
$value
"
);
'call me when page is finished. did recieve second route result
$value
'
);
});
});
},
},
),
),
...
@@ -73,9 +77,11 @@ class _MyAppState extends State<MyApp> {
...
@@ -73,9 +77,11 @@ class _MyAppState extends State<MyApp> {
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
(<
String
,
PageBuilder
>{
'first'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'first'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
_
)
=>
'second'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
FirstRouteWidget
(),
'second'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
_
)
=>
SecondRouteWidget
(),
});
});
}
}
...
@@ -88,7 +94,7 @@ class _MyAppState extends State<MyApp> {
...
@@ -88,7 +94,7 @@ class _MyAppState extends State<MyApp> {
assert
(
child
is
Navigator
,
'child must be Navigator, what is wrong?'
);
assert
(
child
is
Navigator
,
'child must be Navigator, what is wrong?'
);
final
BoostContainerManager
manager
=
BoostContainerManager
(
final
BoostContainerManager
manager
=
BoostContainerManager
(
initNavigator:
child
,
initNavigator:
child
as
Navigator
,
);
);
return
manager
;
return
manager
;
...
@@ -113,11 +119,14 @@ void main() {
...
@@ -113,11 +119,14 @@ void main() {
testWidgets
(
testWidgets
(
'through the `BoostContainerManager.of(context)` method'
,
'through the `BoostContainerManager.of(context)` method'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
var
builderContext
;
BuildContext
builderContext
;
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
(
'context'
:
(
pageName
,
params
,
_
)
=>
Builder
(
<
String
,
PageBuilder
>{
builder:
(
context
)
{
'context'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
_
)
=>
Builder
(
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
builderContext
=
context
;
builderContext
=
context
;
...
@@ -125,7 +134,8 @@ void main() {
...
@@ -125,7 +134,8 @@ void main() {
);
);
},
},
),
),
});
},
);
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -135,28 +145,34 @@ void main() {
...
@@ -135,28 +145,34 @@ void main() {
);
);
//open context page
//open context page
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
.
nativeContainerDidShow
(
"context"
,
{},
"1000000"
);
'context'
,
<
String
,
dynamic
>{},
'1000000'
,
);
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
byType
(
FloatingActionButton
),
findsOneWidget
);
expect
(
find
.
byType
(
FloatingActionButton
),
findsOneWidget
);
//get the context of the Builder
//get the context of the Builder
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
final
isFind
=
BoostContainerManager
.
of
(
builderContext
)
!=
null
;
final
bool
isFind
=
BoostContainerManager
.
of
(
builderContext
)
!=
null
;
expect
(
isFind
,
true
,
expect
(
isFind
,
true
,
reason:
'`BoostContainerManager.of` should be able to '
reason:
'`BoostContainerManager.of` should be able to '
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`'
);
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`'
,
);
},
},
);
);
// testWidgets(
// testWidgets(
// 'through the `BoostContainerManager.of(context)` method',
// 'through the `BoostContainerManager.of(context)` method',
// (WidgetTester tester) async {
// (WidgetTester tester) async {
//
var
builderContext;
//
BuildContext
builderContext;
//
//
// await tester.pumpWidget(
// await tester.pumpWidget(
// MaterialApp(
// MaterialApp(
...
@@ -184,11 +200,13 @@ void main() {
...
@@ -184,11 +200,13 @@ void main() {
testWidgets
(
testWidgets
(
'through the `BoostContainerManager.tryOf(context)` method'
,
'through the `BoostContainerManager.tryOf(context)` method'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
var
builderContext
;
BuildContext
builderContext
;
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
(
'context'
:
(
pageName
,
params
,
_
)
=>
Builder
(
<
String
,
PageBuilder
>{
builder:
(
context
)
{
'context'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
Builder
(
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
builderContext
=
context
;
builderContext
=
context
;
...
@@ -196,7 +214,8 @@ void main() {
...
@@ -196,7 +214,8 @@ void main() {
);
);
},
},
),
),
});
},
);
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -206,21 +225,25 @@ void main() {
...
@@ -206,21 +225,25 @@ void main() {
);
);
//open context page
//open context page
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
.
nativeContainerDidShow
(
"context"
,
{},
"1000000"
);
'context'
,
<
String
,
dynamic
>{},
'1000000'
);
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
byType
(
FloatingActionButton
),
findsOneWidget
);
expect
(
find
.
byType
(
FloatingActionButton
),
findsOneWidget
);
//get the context of the Builder
//get the context of the Builder
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
final
isFind
=
BoostContainerManager
.
tryOf
(
builderContext
)
!=
null
;
final
bool
isFind
=
BoostContainerManager
.
tryOf
(
builderContext
)
!=
null
;
expect
(
isFind
,
true
,
expect
(
isFind
,
true
,
reason:
'`BoostContainerManager.tryOf` should be able to '
reason:
'`BoostContainerManager.tryOf` should be able to '
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`'
);
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`'
,
);
},
},
);
);
},
},
...
@@ -230,11 +253,13 @@ void main() {
...
@@ -230,11 +253,13 @@ void main() {
testWidgets
(
testWidgets
(
'containerCounts should change based on the number of pages'
,
'containerCounts should change based on the number of pages'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
var
builderContext
;
BuildContext
builderContext
;
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
(
'context'
:
(
pageName
,
params
,
_
)
=>
Builder
(
<
String
,
PageBuilder
>{
builder:
(
context
)
{
'context'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
Builder
(
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
return
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
builderContext
=
context
;
builderContext
=
context
;
...
@@ -242,7 +267,8 @@ void main() {
...
@@ -242,7 +267,8 @@ void main() {
);
);
},
},
),
),
});
},
);
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
...
@@ -253,23 +279,24 @@ void main() {
...
@@ -253,23 +279,24 @@ void main() {
//open first context page
//open first context page
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"context"
,
{},
"1000000"
);
.
nativeContainerDidShow
(
'context'
,
<
String
,
dynamic
>{},
'1000000'
);
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
//get the context of the Builder
//get the context of the Builder
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
final
containerManagerState
=
BoostContainerManager
.
of
(
builderContext
);
final
ContainerManagerState
containerManagerState
=
BoostContainerManager
.
of
(
builderContext
);
expect
(
containerManagerState
.
containerCounts
,
1
,
expect
(
containerManagerState
.
containerCounts
,
1
,
reason:
'1 page shown'
);
reason:
'1 page shown'
);
//open second context page
//open second context page
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"context"
,
{},
"2000000"
);
.
nativeContainerDidShow
(
'context'
,
<
String
,
dynamic
>{},
'2000000'
);
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
containerManagerState
.
containerCounts
,
2
,
expect
(
containerManagerState
.
containerCounts
,
2
,
reason:
'2 page shown'
);
reason:
'2 page shown'
);
...
@@ -277,7 +304,7 @@ void main() {
...
@@ -277,7 +304,7 @@ void main() {
//pop second context page
//pop second context page
containerManagerState
.
pop
();
containerManagerState
.
pop
();
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
containerManagerState
.
containerCounts
,
1
,
expect
(
containerManagerState
.
containerCounts
,
1
,
reason:
'second context page closed, Only one page left'
);
reason:
'second context page closed, Only one page left'
);
...
@@ -285,7 +312,7 @@ void main() {
...
@@ -285,7 +312,7 @@ void main() {
//pop last context page
//pop last context page
containerManagerState
.
pop
();
containerManagerState
.
pop
();
await
tester
.
pump
(
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
containerManagerState
.
containerCounts
,
0
,
expect
(
containerManagerState
.
containerCounts
,
0
,
reason:
'last context page closed, no page left'
);
reason:
'last context page closed, no page left'
);
...
...
test/lib/unit/flutter_boost_test.dart
View file @
6f8de4fa
import
'package:flutter_boost/container/container_manager.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter_boost/container/container_manager.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
void
main
(
)
{
TestWidgetsFlutterBinding
.
ensureInitialized
();
TestWidgetsFlutterBinding
.
ensureInitialized
();
test
(
'test onMethodCall'
,
()
async
{
FlutterBoost
.
singleton
.
registerDefaultPageBuilder
(
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
String
_
)
=>
Container
());
FlutterBoost
.
singleton
.
addContainerObserver
(
(
ContainerOperation
operation
,
BoostContainerSettings
settings
)
{},
);
FlutterBoost
.
singleton
.
addBoostContainerLifeCycleObserver
(
(
ContainerLifeCycle
state
,
BoostContainerSettings
settings
)
{},
);
FlutterBoost
.
singleton
.
addBoostNavigatorObserver
(
NavigatorObserver
());
try
{
FlutterBoost
.
singleton
.
open
(
'url'
);
}
catch
(
e
)
{
expect
(
e
,
isException
);
}
try
{
FlutterBoost
.
singleton
.
close
(
'url'
);
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
}
try
{
FlutterBoost
.
singleton
.
closeCurrent
(
result:
<
String
,
dynamic
>{},
exts:
<
String
,
dynamic
>{},
);
}
catch
(
e
)
{
expect
(
e
,
isNoSuchMethodError
);
}
// test('test onMethodCall', () async {
try
{
// FlutterBoost.singleton
FlutterBoost
.
singleton
.
closeByContext
(
// .registerDefaultPageBuilder((pageName, params, _) => Container());
null
,
// FlutterBoost.singleton.addContainerObserver(
result:
<
String
,
dynamic
>{},
// (ContainerOperation operation, BoostContainerSettings settings) {});
exts:
<
String
,
dynamic
>{},
//
);
// FlutterBoost.singleton.addBoostContainerLifeCycleObserver(
}
catch
(
e
)
{
// (ContainerLifeCycle state, BoostContainerSettings settings) {});
expect
(
e
,
isNoSuchMethodError
);
//
}
// FlutterBoost.singleton.addBoostNavigatorObserver(NavigatorObserver());
});
//
// try {
// FlutterBoost.singleton.open("url");
// } catch (e) {
// expect(e, isException);
// }
// try {
// FlutterBoost.singleton.close("url");
// } catch (e) {
// expect(e, isNoSuchMethodError);
// }
// try {
// FlutterBoost.singleton.closeCurrent(result: <String,dynamic>{}, exts: <String,dynamic>{});
// } catch (e) {
// expect(e, isNoSuchMethodError);
// }
//
// try {
// FlutterBoost.singleton.closeByContext(null, result: <String,dynamic>{}, exts: <String,dynamic>{});
// } catch (e) {
// expect(e, isNoSuchMethodError);
// }
// });
}
}
test/lib/unit/page_widget_test.dart
View file @
6f8de4fa
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'page_widgets.dart'
;
import
'page_widgets.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
class
MyApp
extends
StatefulWidget
{
class
MyApp
extends
StatefulWidget
{
@override
@override
...
@@ -15,14 +16,19 @@ class _MyAppState extends State<MyApp> {
...
@@ -15,14 +16,19 @@ class _MyAppState extends State<MyApp> {
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
FlutterBoost
.
singleton
.
registerPageBuilders
({
FlutterBoost
.
singleton
.
registerPageBuilders
(<
String
,
PageBuilder
>{
'embeded'
:
(
pageName
,
params
,
_
)
=>
EmbededFirstRouteWidget
(),
'embeded'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
'first'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
EmbededFirstRouteWidget
(),
'second'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'first'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
'tab'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
FirstRouteWidget
(),
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
'second'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
'flutterPage'
:
(
pageName
,
params
,
_
)
{
SecondRouteWidget
(),
print
(
"flutterPage params:
$params
"
);
'tab'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
TabRouteWidget
(),
'flutterFragment'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
=>
FragmentRouteWidget
(
params
),
'flutterPage'
:
(
String
pageName
,
Map
<
String
,
dynamic
>
params
,
_
)
{
print
(
'flutterPage params:
$params
'
);
return
FlutterRouteWidget
(
params:
params
);
return
FlutterRouteWidget
(
params:
params
);
},
},
...
@@ -40,24 +46,33 @@ class _MyAppState extends State<MyApp> {
...
@@ -40,24 +46,33 @@ class _MyAppState extends State<MyApp> {
}
}
void
_onRoutePushed
(
void
_onRoutePushed
(
String
pageName
,
String
uniqueId
,
Map
params
,
Route
route
,
Future
_
)
{}
String
pageName
,
String
uniqueId
,
Map
<
String
,
dynamic
>
params
,
Route
<
dynamic
>
route
,
Future
<
dynamic
>
_
,
)
{}
}
}
class
TestBoostNavigatorObserver
extends
NavigatorObserver
{
class
TestBoostNavigatorObserver
extends
NavigatorObserver
{
@override
void
didPush
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didPush
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didPush"
);
print
(
'flutterboost#didPush'
);
}
}
@override
void
didPop
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didPop
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didPop"
);
print
(
'flutterboost#didPop'
);
}
}
@override
void
didRemove
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
void
didRemove
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didRemove"
);
print
(
'flutterboost#didRemove'
);
}
}
@override
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
print
(
"flutterboost#didReplace"
);
print
(
'flutterboost#didReplace'
);
}
}
}
}
...
@@ -72,7 +87,7 @@ void main() {
...
@@ -72,7 +87,7 @@ void main() {
);
);
//open firt page
//open firt page
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"first"
,
<
dynamic
,
dynamic
>{},
"1000000"
);
.
nativeContainerDidShow
(
'first'
,
<
String
,
dynamic
>{},
'1000000'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -80,7 +95,7 @@ void main() {
...
@@ -80,7 +95,7 @@ void main() {
//open second page firt(1000000)->second(2000000)
//open second page firt(1000000)->second(2000000)
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"second"
,
<
dynamic
,
dynamic
>{},
"2000000"
);
.
nativeContainerDidShow
(
'second'
,
<
String
,
dynamic
>{},
'2000000'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -89,7 +104,7 @@ void main() {
...
@@ -89,7 +104,7 @@ void main() {
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
//close sencod page firt(1000000)
//close sencod page firt(1000000)
FlutterBoost
.
containerManager
?.
remove
(
"2000000"
);
FlutterBoost
.
containerManager
?.
remove
(
'2000000'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -97,7 +112,7 @@ void main() {
...
@@ -97,7 +112,7 @@ void main() {
// second page ,but pageId is 2000001 firt(1000000)->second(2000001)
// second page ,but pageId is 2000001 firt(1000000)->second(2000001)
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"second"
,
<
dynamic
,
dynamic
>{},
"2000001"
);
.
nativeContainerDidShow
(
'second'
,
<
String
,
dynamic
>{},
'2000001'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -107,7 +122,7 @@ void main() {
...
@@ -107,7 +122,7 @@ void main() {
//reopen firt page second(2000001)->firt(1000000)
//reopen firt page second(2000001)->firt(1000000)
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"first"
,<
dynamic
,
dynamic
>
{},
"1000000"
);
.
nativeContainerDidShow
(
'first'
,
<
String
,
dynamic
>{},
'1000000'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -117,7 +132,7 @@ void main() {
...
@@ -117,7 +132,7 @@ void main() {
// reopen second page and pageId is 2000001 firt(1000000)->second(2000001)
// reopen second page and pageId is 2000001 firt(1000000)->second(2000001)
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"second"
,
<
dynamic
,
dynamic
>{},
"2000001"
);
.
nativeContainerDidShow
(
'second'
,
<
String
,
dynamic
>{},
'2000001'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
@@ -126,24 +141,18 @@ void main() {
...
@@ -126,24 +141,18 @@ void main() {
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
//close firt(1000000) page second(2000001)
//close firt(1000000) page second(2000001)
FlutterBoost
.
containerManager
?.
remove
(
"1000000"
);
FlutterBoost
.
containerManager
?.
remove
(
'1000000'
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'Second'
),
findsOneWidget
);
expect
(
find
.
text
(
'Second'
),
findsOneWidget
);
// open second(2000003)
// open second(2000003)
ContainerCoordinator
.
singleton
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"second"
,
<
dynamic
,
dynamic
>{},
"2000003"
);
.
nativeContainerDidShow
(
'second'
,
<
String
,
dynamic
>{},
'2000003'
);
await
tester
.
idle
();
await
tester
.
idle
();
expect
(
find
.
text
(
'Second'
),
findsOneWidget
);
expect
(
find
.
text
(
'Second'
),
findsOneWidget
);
});
});
}
}
test/lib/unit/page_widgets.dart
View file @
6f8de4fa
...
@@ -7,32 +7,34 @@ class FirstRouteWidget extends StatelessWidget {
...
@@ -7,32 +7,34 @@ class FirstRouteWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
'First Route'
),
title:
const
Text
(
'First Route'
),
),
),
body:
Center
(
body:
Center
(
child:
child:
Column
(
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
children:
<
Widget
>[
<
Widget
>[
RaisedButton
(
RaisedButton
(
child:
Text
(
'First'
),
child:
const
Text
(
'First'
),
onPressed:
()
{
onPressed:
()
{
print
(
"open second page!"
);
print
(
'open second page!'
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
FlutterBoost
.
singleton
.
open
(
'second'
)
.
then
((
Map
<
String
,
dynamic
>
value
)
{
print
(
print
(
"call me when page is finished. did recieve second route result
$value
"
);
'call me when page is finished. did recieve second route result
$value
'
);
});
});
},
},
),
),
RaisedButton
(
RaisedButton
(
child:
Text
(
'Present second route'
),
child:
const
Text
(
'Present second route'
),
onPressed:
()
{
onPressed:
()
{
print
(
"Present second page!"
);
print
(
'Present second page!'
);
FlutterBoost
.
singleton
.
open
(
"second"
,
urlParams:
<
dynamic
,
dynamic
>{
"present"
:
true
}).
then
((
Map
value
)
{
FlutterBoost
.
singleton
.
open
(
'second'
,
urlParams:
<
String
,
dynamic
>{
'present'
:
true
}).
then
((
Map
<
String
,
dynamic
>
value
)
{
print
(
print
(
"call me when page is finished. did recieve second route result
$value
"
);
'call me when page is finished. did recieve second route result
$value
'
);
});
});
},
},
),
),
...
@@ -49,12 +51,14 @@ class EmbededFirstRouteWidget extends StatelessWidget {
...
@@ -49,12 +51,14 @@ class EmbededFirstRouteWidget extends StatelessWidget {
return
Scaffold
(
return
Scaffold
(
body:
Center
(
body:
Center
(
child:
RaisedButton
(
child:
RaisedButton
(
child:
Text
(
'Open second route'
),
child:
const
Text
(
'Open second route'
),
onPressed:
()
{
onPressed:
()
{
print
(
"open second page!"
);
print
(
'open second page!'
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
FlutterBoost
.
singleton
.
open
(
'second'
)
.
then
((
Map
<
String
,
dynamic
>
value
)
{
print
(
print
(
"call me when page is finished. did recieve second route result
$value
"
);
'call me when page is finished. did recieve second route result
$value
'
);
});
});
},
},
),
),
...
@@ -68,19 +72,19 @@ class SecondRouteWidget extends StatelessWidget {
...
@@ -68,19 +72,19 @@ class SecondRouteWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
"Second"
),
title:
const
Text
(
'Second'
),
),
),
body:
Center
(
body:
Center
(
child:
RaisedButton
(
child:
RaisedButton
(
onPressed:
()
{
onPressed:
()
{
// Navigate back to first route when tapped.
// Navigate back to first route when tapped.
BoostContainerSettings
settings
=
final
BoostContainerSettings
settings
=
BoostContainer
.
of
(
context
).
settings
;
BoostContainer
.
of
(
context
).
settings
;
FlutterBoost
.
singleton
.
close
(
settings
.
uniqueId
,
FlutterBoost
.
singleton
.
close
(
settings
.
uniqueId
,
result:
<
dynamic
,
dynamic
>{
"result"
:
"data from second"
});
result:
<
String
,
dynamic
>{
'result'
:
'data from second'
});
},
},
child:
Text
(
'Go back with result!'
),
child:
const
Text
(
'Go back with result!'
),
),
),
),
),
);
);
...
@@ -92,14 +96,14 @@ class TabRouteWidget extends StatelessWidget {
...
@@ -92,14 +96,14 @@ class TabRouteWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
"Tab Route"
),
title:
const
Text
(
'Tab Route'
),
),
),
body:
Center
(
body:
Center
(
child:
RaisedButton
(
child:
RaisedButton
(
onPressed:
()
{
onPressed:
()
{
FlutterBoost
.
singleton
.
open
(
"second"
);
FlutterBoost
.
singleton
.
open
(
'second'
);
},
},
child:
Text
(
'Open second route'
),
child:
const
Text
(
'Open second route'
),
),
),
),
),
);
);
...
@@ -107,8 +111,9 @@ class TabRouteWidget extends StatelessWidget {
...
@@ -107,8 +111,9 @@ class TabRouteWidget extends StatelessWidget {
}
}
class
FlutterRouteWidget
extends
StatefulWidget
{
class
FlutterRouteWidget
extends
StatefulWidget
{
FlutterRouteWidget
({
this
.
params
,
this
.
message
});
const
FlutterRouteWidget
({
this
.
params
,
this
.
message
});
final
Map
params
;
final
Map
<
String
,
dynamic
>
params
;
final
String
message
;
final
String
message
;
@override
@override
...
@@ -116,34 +121,31 @@ class FlutterRouteWidget extends StatefulWidget {
...
@@ -116,34 +121,31 @@ class FlutterRouteWidget extends StatefulWidget {
}
}
class
_FlutterRouteWidgetState
extends
State
<
FlutterRouteWidget
>
{
class
_FlutterRouteWidgetState
extends
State
<
FlutterRouteWidget
>
{
final
TextEditingController
_usernameController
=
TextEditingController
();
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
final
String
message
=
widget
.
message
;
final
String
message
=
widget
.
message
;
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
brightness:
Brightness
.
light
,
brightness:
Brightness
.
light
,
backgroundColor:
Colors
.
white
,
backgroundColor:
Colors
.
white
,
textTheme:
new
TextTheme
(
title:
TextStyle
(
color:
Colors
.
black
))
,
textTheme:
TextTheme
(
title:
TextStyle
(
color:
Colors
.
black
)),
title:
const
Text
(
'flutter_boost_example'
),
title:
Text
(
'flutter_boost_example'
),
),
),
body:
SingleChildScrollView
(
body:
SingleChildScrollView
(
child:
Container
(
child:
Container
(
margin:
const
EdgeInsets
.
all
(
24.0
),
margin:
const
EdgeInsets
.
all
(
24.0
),
child:
Column
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
children:
<
Widget
>[
Container
(
Container
(
margin:
const
EdgeInsets
.
only
(
top:
10.0
,
bottom:
20.0
),
margin:
const
EdgeInsets
.
only
(
top:
10.0
,
bottom:
20.0
),
child:
Text
(
child:
Text
(
message
??
"This is a flutter activity
\n
params:
${widget.params}
"
,
message
??
'This is a flutter activity
\n
params:
${widget.params}
'
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
),
alignment:
AlignmentDirectional
.
center
,
alignment:
AlignmentDirectional
.
center
,
),
),
// Expanded(child: Container()),
const
CupertinoTextField
(
const
CupertinoTextField
(
prefix:
Icon
(
prefix:
Icon
(
CupertinoIcons
.
person_solid
,
CupertinoIcons
.
person_solid
,
...
@@ -155,7 +157,10 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -155,7 +157,10 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
textCapitalization:
TextCapitalization
.
words
,
textCapitalization:
TextCapitalization
.
words
,
autocorrect:
false
,
autocorrect:
false
,
decoration:
BoxDecoration
(
decoration:
BoxDecoration
(
border:
Border
(
bottom:
BorderSide
(
width:
0.0
,
color:
CupertinoColors
.
inactiveGray
)),
border:
Border
(
bottom:
BorderSide
(
width:
0.0
,
color:
CupertinoColors
.
inactiveGray
),
),
),
),
placeholder:
'Name'
,
placeholder:
'Name'
,
),
),
...
@@ -167,14 +172,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -167,14 +172,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
child:
Text
(
child:
Text
(
'open native page'
,
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
.
open
(
"sample://nativePage"
,
urlParams:
<
dynamic
,
dynamic
>{
'sample://nativePage'
,
"query"
:
{
"aaa"
:
"bbb"
}
urlParams:
<
String
,
dynamic
>{
}),
'query'
:
<
String
,
dynamic
>{
'aaa'
:
'bbb'
},
},
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -184,14 +192,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -184,14 +192,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
child:
Text
(
child:
Text
(
'open first'
,
'open first'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
.
open
(
"first"
,
urlParams:
<
dynamic
,
dynamic
>{
'first'
,
"query"
:
{
"aaa"
:
"bbb"
}
urlParams:
<
String
,
dynamic
>{
}),
'query'
:
<
String
,
dynamic
>{
'aaa'
:
'bbb'
},
},
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -201,14 +212,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -201,14 +212,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
child:
Text
(
child:
Text
(
'open second'
,
'open second'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
.
open
(
"second"
,
urlParams:
<
dynamic
,
dynamic
>{
'second'
,
"query"
:
{
"aaa"
:
"bbb"
}
urlParams:
<
String
,
dynamic
>{
}),
'query'
:
<
String
,
dynamic
>{
'aaa'
:
'bbb'
},
},
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -218,14 +232,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -218,14 +232,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
child:
Text
(
child:
Text
(
'open tab'
,
'open tab'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
.
open
(
"tab"
,
urlParams:
<
dynamic
,
dynamic
>{
'tab'
,
"query"
:
{
"aaa"
:
"bbb"
}
urlParams:
<
String
,
dynamic
>{
}),
'query'
:
<
String
,
dynamic
>{
'aaa'
:
'bbb'
}
},
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -235,14 +252,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -235,14 +252,17 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
child:
Text
(
child:
Text
(
'open flutter page'
,
'open flutter page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
.
open
(
"sample://flutterPage"
,
urlParams:
<
dynamic
,
dynamic
>
{
'sample://flutterPage'
,
"query"
:
{
"aaa"
:
"bbb"
}
urlParams:
<
String
,
dynamic
>{
}),
'query'
:
<
String
,
dynamic
>{
'aaa'
:
'bbb'
}
},
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -254,11 +274,12 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -254,11 +274,12 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
{
onTap:
()
{
Navigator
.
push
<
dynamic
>(
context
,
Navigator
.
push
<
dynamic
>(
MaterialPageRoute
<
dynamic
>(
builder:
(
_
)
=>
PushWidget
()));
context
,
MaterialPageRoute
<
dynamic
>(
builder:
(
_
)
=>
PushWidget
()),
);
},
},
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
padding:
const
EdgeInsets
.
all
(
8.0
),
...
@@ -268,8 +289,7 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -268,8 +289,7 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
'push Platform demo'
,
'push Platform demo'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
{
onTap:
()
{},
},
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -280,12 +300,11 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -280,12 +300,11 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
'open flutter fragment page'
,
'open flutter fragment page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
=>
FlutterBoost
.
singleton
onTap:
()
=>
.
open
(
"sample://flutterFragmentPage"
),
FlutterBoost
.
singleton
.
open
(
'sample://flutterFragmentPage'
),
),
),
],
],
),
),
),
),
),
),
);
);
...
@@ -293,15 +312,15 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
...
@@ -293,15 +312,15 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
}
}
class
FragmentRouteWidget
extends
StatelessWidget
{
class
FragmentRouteWidget
extends
StatelessWidget
{
final
Map
params
;
const
FragmentRouteWidget
(
this
.
params
)
;
FragmentRouteWidget
(
this
.
params
)
;
final
Map
<
String
,
dynamic
>
params
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
'flutter_boost_example'
),
title:
const
Text
(
'flutter_boost_example'
),
),
),
body:
Column
(
body:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
...
@@ -309,7 +328,7 @@ class FragmentRouteWidget extends StatelessWidget {
...
@@ -309,7 +328,7 @@ class FragmentRouteWidget extends StatelessWidget {
Container
(
Container
(
margin:
const
EdgeInsets
.
only
(
top:
80.0
),
margin:
const
EdgeInsets
.
only
(
top:
80.0
),
child:
Text
(
child:
Text
(
"This is a flutter fragment"
,
'This is a flutter fragment'
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
),
alignment:
AlignmentDirectional
.
center
,
alignment:
AlignmentDirectional
.
center
,
...
@@ -317,7 +336,7 @@ class FragmentRouteWidget extends StatelessWidget {
...
@@ -317,7 +336,7 @@ class FragmentRouteWidget extends StatelessWidget {
Container
(
Container
(
margin:
const
EdgeInsets
.
only
(
top:
32.0
),
margin:
const
EdgeInsets
.
only
(
top:
32.0
),
child:
Text
(
child:
Text
(
params
[
'tag'
]
??
''
,
'
${params['tag']}
'
??
''
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
red
),
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
red
),
),
),
alignment:
AlignmentDirectional
.
center
,
alignment:
AlignmentDirectional
.
center
,
...
@@ -332,7 +351,7 @@ class FragmentRouteWidget extends StatelessWidget {
...
@@ -332,7 +351,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open native page'
,
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://nativePage"
),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
'sample://nativePage'
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -343,7 +362,7 @@ class FragmentRouteWidget extends StatelessWidget {
...
@@ -343,7 +362,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter page'
,
'open flutter page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage"
),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
'sample://flutterPage'
),
),
),
InkWell
(
InkWell
(
child:
Container
(
child:
Container
(
...
@@ -355,7 +374,7 @@ class FragmentRouteWidget extends StatelessWidget {
...
@@ -355,7 +374,7 @@ class FragmentRouteWidget extends StatelessWidget {
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
)),
onTap:
()
=>
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterFragmentPage"
),
FlutterBoost
.
singleton
.
open
(
'sample://flutterFragmentPage'
),
)
)
],
],
),
),
...
@@ -373,13 +392,13 @@ class _PushWidgetState extends State<PushWidget> {
...
@@ -373,13 +392,13 @@ class _PushWidgetState extends State<PushWidget> {
@override
@override
void
initState
()
{
void
initState
()
{
// TODO: implement initState
// TODO
(unknown)
: implement initState
super
.
initState
();
super
.
initState
();
}
}
@override
@override
void
didChangeDependencies
()
{
void
didChangeDependencies
()
{
// TODO: implement didChangeDependencies
// TODO
(unknown)
: implement didChangeDependencies
super
.
didChangeDependencies
();
super
.
didChangeDependencies
();
// if (_backPressedListenerUnsub == null) {
// if (_backPressedListenerUnsub == null) {
...
@@ -395,13 +414,13 @@ class _PushWidgetState extends State<PushWidget> {
...
@@ -395,13 +414,13 @@ class _PushWidgetState extends State<PushWidget> {
@override
@override
void
dispose
()
{
void
dispose
()
{
// TODO: implement dispose
// TODO
(unknown)
: implement dispose
super
.
dispose
();
super
.
dispose
();
_backPressedListenerUnsub
?.
call
();
_backPressedListenerUnsub
?.
call
();
}
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
FlutterRouteWidget
(
message:
"Pushed Widget"
);
return
const
FlutterRouteWidget
(
message:
'Pushed Widget'
);
}
}
}
}
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