Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flutter_boost_1.22.4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢冠章
flutter_boost_1.22.4
Commits
7d7ac629
Commit
7d7ac629
authored
Feb 20, 2020
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test case
parent
47c27577
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
490 additions
and
38 deletions
+490
-38
test/lib/unit/flutter_boost_test.dart
test/lib/unit/flutter_boost_test.dart
+83
-38
test/lib/unit/page_widgets.dart
test/lib/unit/page_widgets.dart
+407
-0
No files found.
test/lib/unit/flutter_boost_test.dart
View file @
7d7ac629
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'page_widgets.dart'
;
import
'package:flutter_boost/container/container_coordinator.dart'
;
void
main
(
)
{
const
MethodChannel
channel
=
MethodChannel
(
'flutter_boost'
);
final
List
<
MethodCall
>
log
=
<
MethodCall
>[];
dynamic
response
;
channel
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
print
(
methodCall
);
log
.
add
(
methodCall
);
return
response
;
});
class
MyApp
extends
StatefulWidget
{
@override
_MyAppState
createState
()
=>
_MyAppState
();
}
tearDown
(()
{
log
.
clear
();
});
class
_MyAppState
extends
State
<
MyApp
>
{
@override
void
initState
()
{
super
.
initState
();
FlutterBoost
.
singleton
.
registerPageBuilders
({
'embeded'
:
(
pageName
,
params
,
_
)
=>
EmbededFirstRouteWidget
(),
'first'
:
(
pageName
,
params
,
_
)
=>
FirstRouteWidget
(),
'second'
:
(
pageName
,
params
,
_
)
=>
SecondRouteWidget
(),
'tab'
:
(
pageName
,
params
,
_
)
=>
TabRouteWidget
(),
'flutterFragment'
:
(
pageName
,
params
,
_
)
=>
FragmentRouteWidget
(
params
),
'flutterPage'
:
(
pageName
,
params
,
_
)
{
print
(
"flutterPage params:
$params
"
);
return
FlutterRouteWidget
(
params:
params
);
},
});
FlutterBoost
.
singleton
.
addBoostNavigatorObserver
(
TestBoostNavigatorObserver
());
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Flutter Boost example'
,
builder:
FlutterBoost
.
init
(
postPush:
_onRoutePushed
),
home:
Container
());
}
void
_onRoutePushed
(
String
pageName
,
String
uniqueId
,
Map
params
,
Route
route
,
Future
_
)
{}
}
class
TestBoostNavigatorObserver
extends
NavigatorObserver
{
void
didPush
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didPush"
);
}
void
didPop
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didPop"
);
}
void
didRemove
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
print
(
"flutterboost#didRemove"
);
}
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
print
(
"flutterboost#didReplace"
);
}
}
void
main
(
)
{
TestWidgetsFlutterBinding
.
ensureInitialized
();
group
(
'flutter_boost'
,
()
{
response
=
null
;
testWidgets
(
'test iOS edge swipe then drop back at starting point works'
,
(
WidgetTester
tester
)
async
{
//push app
await
tester
.
pumpWidget
(
MyApp
(),
);
test
(
'init successfully'
,
()
async
{
Function
builder
=
FlutterBoost
.
init
();
//open firt page
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"first"
,
{},
"1000000"
);
expect
(
builder
.
runtimeType
,
TransitionBuilder
,
);
});
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
test
(
'open successfully'
,
()
async
{
Future
<
Map
<
dynamic
,
dynamic
>>
result
=
FlutterBoost
.
singleton
.
open
(
"url"
);
expect
(
find
.
text
(
'First'
),
findsOneWidget
);
expect
(
result
,
isInstanceOf
<
Future
<
Map
<
dynamic
,
dynamic
>>>(),
);
});
//open second page
ContainerCoordinator
.
singleton
.
nativeContainerDidShow
(
"second"
,
{},
"2000000"
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'Second'
),
findsOneWidget
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
//close sencod page
FlutterBoost
.
containerManager
?.
remove
(
"2000000"
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// test('close successfully', () async {
// Future<bool> result = FlutterBoost.singleton.close("id");
//
// expect(
// result,
// isInstanceOf<bool>(),
// );
// });
expect
(
find
.
text
(
'First'
),
findsOneWidget
);
});
...
...
test/lib/unit/page_widgets.dart
0 → 100755
View file @
7d7ac629
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_boost/flutter_boost.dart'
;
class
FirstRouteWidget
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'First Route'
),
),
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
RaisedButton
(
child:
Text
(
'First'
),
onPressed:
()
{
print
(
"open second page!"
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
print
(
"call me when page is finished. did recieve second route result
$value
"
);
});
},
),
RaisedButton
(
child:
Text
(
'Present second route'
),
onPressed:
()
{
print
(
"Present second page!"
);
FlutterBoost
.
singleton
.
open
(
"second"
,
urlParams:
{
"present"
:
true
}).
then
((
Map
value
)
{
print
(
"call me when page is finished. did recieve second route result
$value
"
);
});
},
),
],
),
),
);
}
}
class
EmbededFirstRouteWidget
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
Center
(
child:
RaisedButton
(
child:
Text
(
'Open second route'
),
onPressed:
()
{
print
(
"open second page!"
);
FlutterBoost
.
singleton
.
open
(
"second"
).
then
((
Map
value
)
{
print
(
"call me when page is finished. did recieve second route result
$value
"
);
});
},
),
),
);
}
}
class
SecondRouteWidget
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"Second"
),
),
body:
Center
(
child:
RaisedButton
(
onPressed:
()
{
// Navigate back to first route when tapped.
BoostContainerSettings
settings
=
BoostContainer
.
of
(
context
).
settings
;
FlutterBoost
.
singleton
.
close
(
settings
.
uniqueId
,
result:
{
"result"
:
"data from second"
});
},
child:
Text
(
'Go back with result!'
),
),
),
);
}
}
class
TabRouteWidget
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"Tab Route"
),
),
body:
Center
(
child:
RaisedButton
(
onPressed:
()
{
FlutterBoost
.
singleton
.
open
(
"second"
);
},
child:
Text
(
'Open second route'
),
),
),
);
}
}
class
FlutterRouteWidget
extends
StatefulWidget
{
FlutterRouteWidget
({
this
.
params
,
this
.
message
});
final
Map
params
;
final
String
message
;
@override
_FlutterRouteWidgetState
createState
()
=>
_FlutterRouteWidgetState
();
}
class
_FlutterRouteWidgetState
extends
State
<
FlutterRouteWidget
>
{
final
TextEditingController
_usernameController
=
TextEditingController
();
@override
Widget
build
(
BuildContext
context
)
{
final
String
message
=
widget
.
message
;
return
Scaffold
(
appBar:
AppBar
(
brightness:
Brightness
.
light
,
backgroundColor:
Colors
.
white
,
textTheme:
new
TextTheme
(
title:
TextStyle
(
color:
Colors
.
black
))
,
title:
Text
(
'flutter_boost_example'
),
),
body:
SingleChildScrollView
(
child:
Container
(
margin:
const
EdgeInsets
.
all
(
24.0
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
only
(
top:
10.0
,
bottom:
20.0
),
child:
Text
(
message
??
"This is a flutter activity
\n
params:
${widget.params}
"
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
alignment:
AlignmentDirectional
.
center
,
),
// Expanded(child: Container()),
const
CupertinoTextField
(
prefix:
Icon
(
CupertinoIcons
.
person_solid
,
color:
CupertinoColors
.
lightBackgroundGray
,
size:
28.0
,
),
padding:
EdgeInsets
.
symmetric
(
horizontal:
6.0
,
vertical:
12.0
),
clearButtonMode:
OverlayVisibilityMode
.
editing
,
textCapitalization:
TextCapitalization
.
words
,
autocorrect:
false
,
decoration:
BoxDecoration
(
border:
Border
(
bottom:
BorderSide
(
width:
0.0
,
color:
CupertinoColors
.
inactiveGray
)),
),
placeholder:
'Name'
,
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://nativePage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open first'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"first"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open second'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"second"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open tab'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"tab"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage"
,
urlParams:
{
"query"
:
{
"aaa"
:
"bbb"
}
}),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'push flutter widget'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
_
)
=>
PushWidget
()));
},
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'push Platform demo'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
{
},
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter fragment page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterFragmentPage"
),
),
],
),
),
),
);
}
}
class
FragmentRouteWidget
extends
StatelessWidget
{
final
Map
params
;
FragmentRouteWidget
(
this
.
params
);
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'flutter_boost_example'
),
),
body:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
only
(
top:
80.0
),
child:
Text
(
"This is a flutter fragment"
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
blue
),
),
alignment:
AlignmentDirectional
.
center
,
),
Container
(
margin:
const
EdgeInsets
.
only
(
top:
32.0
),
child:
Text
(
params
[
'tag'
]
??
''
,
style:
TextStyle
(
fontSize:
28.0
,
color:
Colors
.
red
),
),
alignment:
AlignmentDirectional
.
center
,
),
Expanded
(
child:
Container
()),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open native page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://nativePage"
),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
all
(
8.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterPage"
),
),
InkWell
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
8.0
),
margin:
const
EdgeInsets
.
fromLTRB
(
8.0
,
8.0
,
8.0
,
80.0
),
color:
Colors
.
yellow
,
child:
Text
(
'open flutter fragment page'
,
style:
TextStyle
(
fontSize:
22.0
,
color:
Colors
.
black
),
)),
onTap:
()
=>
FlutterBoost
.
singleton
.
open
(
"sample://flutterFragmentPage"
),
)
],
),
);
}
}
class
PushWidget
extends
StatefulWidget
{
@override
_PushWidgetState
createState
()
=>
_PushWidgetState
();
}
class
_PushWidgetState
extends
State
<
PushWidget
>
{
VoidCallback
_backPressedListenerUnsub
;
@override
void
initState
()
{
// TODO: implement initState
super
.
initState
();
}
@override
void
didChangeDependencies
()
{
// TODO: implement didChangeDependencies
super
.
didChangeDependencies
();
// if (_backPressedListenerUnsub == null) {
// _backPressedListenerUnsub =
// BoostContainer.of(context).addBackPressedListener(() {
// if (BoostContainer.of(context).onstage &&
// ModalRoute.of(context).isCurrent) {
// Navigator.pop(context);
// }
// });
// }
}
@override
void
dispose
()
{
// TODO: implement dispose
super
.
dispose
();
_backPressedListenerUnsub
?.
call
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
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