Commit 50022e7f authored by AlexVincent525's avatar AlexVincent525

🎨 Improve code in example.

parent 4871b571
...@@ -17,7 +17,7 @@ class _MyAppState extends State<MyApp> { ...@@ -17,7 +17,7 @@ class _MyAppState extends State<MyApp> {
super.initState(); super.initState();
FlutterBoost.singleton.registerPageBuilders({ FlutterBoost.singleton.registerPageBuilders({
'embeded': (pageName, params, _)=>EmbededFirstRouteWidget(), 'embeded': (pageName, params, _) => EmbeddedFirstRouteWidget(),
'first': (pageName, params, _) => FirstRouteWidget(), 'first': (pageName, params, _) => FirstRouteWidget(),
'firstFirst': (pageName, params, _) => FirstFirstRouteWidget(), 'firstFirst': (pageName, params, _) => FirstFirstRouteWidget(),
'second': (pageName, params, _) => SecondRouteWidget(), 'second': (pageName, params, _) => SecondRouteWidget(),
...@@ -25,14 +25,16 @@ class _MyAppState extends State<MyApp> { ...@@ -25,14 +25,16 @@ class _MyAppState extends State<MyApp> {
'tab': (pageName, params, _) => TabRouteWidget(), 'tab': (pageName, params, _) => TabRouteWidget(),
'platformView': (pageName, params, _) => PlatformRouteWidget(), 'platformView': (pageName, params, _) => PlatformRouteWidget(),
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params), 'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
///可以在native层通过 getContainerParams 来传递参数 ///可以在native层通过 getContainerParams 来传递参数
'flutterPage': (pageName, params, _) { 'flutterPage': (pageName, params, _) {
print("flutterPage params:$params"); print("flutterPage params:$params");
return FlutterRouteWidget(params:params); return FlutterRouteWidget(params: params);
}, },
}); });
FlutterBoost.singleton.addBoostNavigatorObserver(TestBoostNavigatorObserver()); FlutterBoost.singleton
.addBoostNavigatorObserver(TestBoostNavigatorObserver());
} }
@override @override
...@@ -40,18 +42,15 @@ class _MyAppState extends State<MyApp> { ...@@ -40,18 +42,15 @@ class _MyAppState extends State<MyApp> {
return MaterialApp( return MaterialApp(
title: 'Flutter Boost example', title: 'Flutter Boost example',
builder: FlutterBoost.init(postPush: _onRoutePushed), builder: FlutterBoost.init(postPush: _onRoutePushed),
home: Container( home: Container(color: Colors.white));
color:Colors.white
));
} }
void _onRoutePushed( void _onRoutePushed(
String pageName, String uniqueId, Map params, Route route, Future _) { String pageName, String uniqueId, Map params, Route route, Future _) {}
}
} }
class TestBoostNavigatorObserver extends NavigatorObserver{
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
class TestBoostNavigatorObserver extends NavigatorObserver {
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
print("flutterboost#didPush"); print("flutterboost#didPush");
} }
...@@ -67,4 +66,3 @@ class TestBoostNavigatorObserver extends NavigatorObserver{ ...@@ -67,4 +66,3 @@ class TestBoostNavigatorObserver extends NavigatorObserver{
print("flutterboost#didReplace"); print("flutterboost#didReplace");
} }
} }
...@@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart'; ...@@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
typedef void TextViewCreatedCallback(TextViewController controller); typedef TextViewCreatedCallback = void Function(TextViewController controller);
class TextView extends StatefulWidget { class TextView extends StatefulWidget {
const TextView({ const TextView({
...@@ -34,13 +34,13 @@ class _TextViewState extends State<TextView> { ...@@ -34,13 +34,13 @@ class _TextViewState extends State<TextView> {
if (widget.onTextViewCreated == null) { if (widget.onTextViewCreated == null) {
return; return;
} }
widget.onTextViewCreated(new TextViewController._(id)); widget.onTextViewCreated(TextViewController._(id));
} }
} }
class TextViewController { class TextViewController {
TextViewController._(int id) TextViewController._(int id)
: _channel = new MethodChannel('plugins.felix.angelov/textview_$id'); : _channel = MethodChannel('plugins.felix.angelov/textview_$id');
final MethodChannel _channel; final MethodChannel _channel;
...@@ -48,4 +48,4 @@ class TextViewController { ...@@ -48,4 +48,4 @@ class TextViewController {
assert(text != null); assert(text != null);
return _channel.invokeMethod('setText', text); return _channel.invokeMethod('setText', text);
} }
} }
\ No newline at end of file
...@@ -5,11 +5,10 @@ import 'package:flutter_boost_example/platform_view.dart'; ...@@ -5,11 +5,10 @@ import 'package:flutter_boost_example/platform_view.dart';
class FirstRouteWidget extends StatefulWidget { class FirstRouteWidget extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() => _FirstRouteWidgetState();
return new _FirstRouteWidgetState();
}
} }
class _FirstRouteWidgetState extends State<FirstRouteWidget>{
class _FirstRouteWidgetState extends State<FirstRouteWidget> {
_FirstRouteWidgetState(); _FirstRouteWidgetState();
@override @override
...@@ -45,80 +44,86 @@ class _FirstRouteWidgetState extends State<FirstRouteWidget>{ ...@@ -45,80 +44,86 @@ class _FirstRouteWidgetState extends State<FirstRouteWidget>{
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('First Route')),
title: 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('Open native page'), child: const Text('Open native page'),
onPressed: () { onPressed: () {
print("open natve page!"); print('open natve page!');
FlutterBoost.singleton.open("native").then((Map value) { FlutterBoost.singleton
print( .open('native')
"call me when page is finished. did recieve native route result $value"); .then((Map<String, dynamic> value) {
}); print(
}, 'call me when page is finished. did recieve native route result $value');
), });
RaisedButton( },
child: Text('Open FF route'), ),
onPressed: () { RaisedButton(
print("open FF page!"); child: const Text('Open FF route'),
FlutterBoost.singleton.open("firstFirst").then((Map value) { onPressed: () {
print( print('open FF page!');
"call me when page is finished. did recieve FF route result $value"); FlutterBoost.singleton
}); .open('firstFirst')
}, .then((Map<String, dynamic> value) {
), print(
RaisedButton( 'call me when page is finished. did recieve FF route result $value');
child: Text('Open second route1'), });
onPressed: () { },
print("open second page!"); ),
FlutterBoost.singleton.open("second").then((Map value) { RaisedButton(
print( child: const Text('Open second route1'),
"call me when page is finished. did recieve second route result $value"); onPressed: () {
}); print('open second page!');
}, FlutterBoost.singleton
), .open('second')
.then((Map<String, dynamic> value) {
RaisedButton( print(
child: Text('Present second stateful route'), 'call me when page is finished. did recieve second route result $value');
onPressed: () { });
print("Present second stateful page!"); },
FlutterBoost.singleton.open("secondStateful",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) { ),
print( RaisedButton(
"call me when page is finished. did recieve second stateful route result $value"); child: const Text('Present second stateful route'),
}); onPressed: () {
}, print('Present second stateful page!');
), FlutterBoost.singleton.open('secondStateful',
RaisedButton( urlParams: <String, dynamic>{
child: Text('Present second route'), 'present': true
onPressed: () { }).then((Map<String, dynamic> value) {
print("Present second page!"); print(
FlutterBoost.singleton.open("second",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) { 'call me when page is finished. did recieve second stateful route result $value');
print( });
"call me when page is finished. did recieve second route result $value"); },
}); ),
}, RaisedButton(
), child: const Text('Present second route'),
], onPressed: () {
print('Present second page!');
FlutterBoost.singleton.open('second',
urlParams: <String, dynamic>{
'present': true
}).then((Map<String, dynamic> value) {
print(
'call me when page is finished. did recieve second route result $value');
});
},
),
],
), ),
), ),
); );
} }
} }
class FirstFirstRouteWidget extends StatefulWidget { class FirstFirstRouteWidget extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() => _FirstFirstRouteWidgetState();
return new _FirstFirstRouteWidgetState();
}
} }
class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{ class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget> {
_FirstFirstRouteWidgetState(); _FirstFirstRouteWidgetState();
@override @override
...@@ -154,20 +159,18 @@ class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{ ...@@ -154,20 +159,18 @@ class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('First Route')),
title: Text('First Route'),
),
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
child: Text('Open first route'), child: const Text('Open first route'),
onPressed: () { onPressed: () {
print('open first page again!');
print("open first page again!"); FlutterBoost.singleton
FlutterBoost.singleton.open("first").then((Map value){ .open('first')
print("did recieve first route result"); .then((Map<String, dynamic> value) {
print("did recieve first route result $value"); print('did recieve first route result');
print('did recieve first route result $value');
}); });
}, },
), ),
), ),
...@@ -175,34 +178,33 @@ class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{ ...@@ -175,34 +178,33 @@ class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{
} }
} }
class EmbededFirstRouteWidget extends StatefulWidget { class EmbeddedFirstRouteWidget extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() => _EmbeddedFirstRouteWidgetState();
// TODO: implement createState
return _EmbededFirstRouteWidgetState();
}
} }
class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> { class _EmbeddedFirstRouteWidgetState extends State<EmbeddedFirstRouteWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('_EmbededFirstRouteWidgetState build called!'); print('_EmbededFirstRouteWidgetState build called!');
return Scaffold( return Scaffold(
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
child: Text('Open second route2'), child: const Text('Open second route2'),
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');
}); });
}, },
), ),
), ),
); );
} }
@override @override
void dispose() { void dispose() {
print('[XDEBUG]:_EmbededFirstRouteWidgetState disposing~'); print('[XDEBUG]:_EmbededFirstRouteWidgetState disposing~');
...@@ -212,29 +214,24 @@ class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> { ...@@ -212,29 +214,24 @@ class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> {
class SecondStatefulRouteWidget extends StatefulWidget { class SecondStatefulRouteWidget extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() => _SecondStatefulRouteWidgetState();
// TODO: implement createState
return _SecondStatefulRouteWidgetState();
}
} }
class _SecondStatefulRouteWidgetState extends State<SecondStatefulRouteWidget>{
class _SecondStatefulRouteWidgetState extends State<SecondStatefulRouteWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('SecondStateful Route')),
title: Text("SecondStateful Route"),
),
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
// Navigate back to first route when tapped. // Navigate back to first route when tapped.
final BoostContainerSettings settings =
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!'),
), ),
), ),
); );
...@@ -251,20 +248,19 @@ class SecondRouteWidget extends StatelessWidget { ...@@ -251,20 +248,19 @@ class SecondRouteWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('Second Route')),
title: Text("Second Route"),
),
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
// Navigate back to first route when tapped. // Navigate back to first route when tapped.
final BoostContainerSettings settings =
BoostContainerSettings settings =
BoostContainer.of(context).settings; BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId, FlutterBoost.singleton.close(
result: <dynamic,dynamic>{"result": "data from second"}); settings.uniqueId,
result: <String, dynamic>{'result': 'data from second'},
);
}, },
child: Text('Go back with result!'), child: const Text('Go back with result!'),
), ),
), ),
); );
...@@ -275,15 +271,13 @@ class TabRouteWidget extends StatelessWidget { ...@@ -275,15 +271,13 @@ class TabRouteWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('Tab Route')),
title: 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 route3'), child: const Text('Open second route3'),
), ),
), ),
); );
...@@ -294,17 +288,17 @@ class PlatformRouteWidget extends StatelessWidget { ...@@ -294,17 +288,17 @@ class PlatformRouteWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('Platform Route')),
title:Text("Platform Route"),
),
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
child: TextView(), child: const TextView(),
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');
}); });
}, },
), ),
...@@ -312,9 +306,11 @@ class PlatformRouteWidget extends StatelessWidget { ...@@ -312,9 +306,11 @@ class PlatformRouteWidget 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
...@@ -322,178 +318,199 @@ class FlutterRouteWidget extends StatefulWidget { ...@@ -322,178 +318,199 @@ 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: const 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 ??
style: TextStyle(fontSize: 28.0, color: Colors.blue), 'This is a flutter activity \n params:${widget.params}',
), style: TextStyle(fontSize: 28.0, color: Colors.blue),
alignment: AlignmentDirectional.center,
), ),
// Expanded(child: Container()), alignment: AlignmentDirectional.center,
const CupertinoTextField( ),
prefix: Icon( const CupertinoTextField(
CupertinoIcons.person_solid, prefix: Icon(
color: CupertinoColors.lightBackgroundGray, CupertinoIcons.person_solid,
size: 28.0, 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),
), ),
padding: EdgeInsets.symmetric(horizontal: 6.0, vertical: 12.0), ),
clearButtonMode: OverlayVisibilityMode.editing, placeholder: 'Name',
textCapitalization: TextCapitalization.words, ),
autocorrect: false, InkWell(
decoration: BoxDecoration( child: Container(
border: Border(bottom: BorderSide(width: 0.0, color: CupertinoColors.inactiveGray)), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: const Text(
'open native page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
), ),
placeholder: 'Name',
), ),
InkWell(
child: Container( /// 后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
padding: const EdgeInsets.all(8.0), /// 例如:sample://nativePage?aaa=bbb
margin: const EdgeInsets.all(8.0), onTap: () => FlutterBoost.singleton.open(
color: Colors.yellow, 'sample://nativePage',
child: Text( urlParams: <String, dynamic>{
'open native page', 'query': <String, dynamic>{'aaa': 'bbb'}
style: TextStyle(fontSize: 22.0, color: Colors.black), },
)), ),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。 InkWell(
///例如:sample://nativePage?aaa=bbb child: Container(
onTap: () => FlutterBoost.singleton padding: const EdgeInsets.all(8.0),
.open("sample://nativePage", urlParams: <dynamic,dynamic>{ margin: const EdgeInsets.all(8.0),
"query": {"aaa": "bbb"} color: Colors.yellow,
}), child: const Text(
'open first',
style: TextStyle(fontSize: 22.0, color: Colors.black),
),
), ),
InkWell(
child: Container( /// 后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
padding: const EdgeInsets.all(8.0), /// 例如:sample://nativePage?aaa=bbb
margin: const EdgeInsets.all(8.0), onTap: () => FlutterBoost.singleton.open(
color: Colors.yellow, 'first',
child: Text( urlParams: <String, dynamic>{
'open first', 'query': <String, dynamic>{'aaa': 'bbb'}
style: TextStyle(fontSize: 22.0, color: Colors.black), },
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () => FlutterBoost.singleton
.open("first", urlParams: <dynamic,dynamic>{
"query": {"aaa": "bbb"}
}),
), ),
InkWell( ),
child: Container( InkWell(
padding: const EdgeInsets.all(8.0), child: Container(
margin: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
color: Colors.yellow, margin: const EdgeInsets.all(8.0),
child: Text( color: Colors.yellow,
'open second', child: const Text(
style: TextStyle(fontSize: 22.0, color: Colors.black), '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:<dynamic,dynamic> {
"query": {"aaa": "bbb"}
}),
), ),
InkWell(
child: Container( /// 后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
padding: const EdgeInsets.all(8.0), /// 例如:sample://nativePage?aaa=bbb
margin: const EdgeInsets.all(8.0), onTap: () => FlutterBoost.singleton.open(
color: Colors.yellow, 'second',
child: Text( urlParams: <String, dynamic>{
'open tab', 'query': <String, dynamic>{'aaa': 'bbb'}
style: TextStyle(fontSize: 22.0, color: Colors.black), },
)),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () => FlutterBoost.singleton
.open("tab", urlParams:<dynamic,dynamic> {
"query": {"aaa": "bbb"}
}),
), ),
InkWell( ),
child: Container( InkWell(
padding: const EdgeInsets.all(8.0), child: Container(
margin: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
color: Colors.yellow, margin: const EdgeInsets.all(8.0),
child: Text( color: Colors.yellow,
'open flutter page', child: const Text(
style: TextStyle(fontSize: 22.0, color: Colors.black), 'open tab',
)), style: TextStyle(fontSize: 22.0, color: Colors.black),
),
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () => FlutterBoost.singleton
.open("sample://flutterPage", urlParams:<dynamic,dynamic> {
"query": {"aaa": "bbb"}
}),
), ),
InkWell(
child: Container( /// 后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
padding: const EdgeInsets.all(8.0), /// 例如:sample://nativePage?aaa=bbb
margin: const EdgeInsets.all(8.0), onTap: () => FlutterBoost.singleton.open(
color: Colors.yellow, 'tab',
child: Text( urlParams: <String, dynamic>{
'push flutter widget', 'query': <String, dynamic>{'aaa': 'bbb'}
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () {
Navigator.push<dynamic>(context,
MaterialPageRoute<dynamic>(builder: (_) => PushWidget()));
}, },
), ),
),
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: const 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: <String, dynamic>{
'query': <String, dynamic>{'aaa': 'bbb'}
},
),
),
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: const Text(
'push flutter widget',
style: TextStyle(fontSize: 22.0, color: Colors.black),
),
),
onTap: () {
Navigator.push<dynamic>(
context,
MaterialPageRoute<dynamic>(builder: (_) => PushWidget()),
);
},
),
InkWell( InkWell(
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0),
color: Colors.yellow, color: Colors.yellow,
child: Text( child: const Text(
'push Platform demo', 'push Platform demo',
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: (_) => PlatformRouteWidget())); context,
MaterialPageRoute<dynamic>(
builder: (_) => PlatformRouteWidget()),
);
}, },
), ),
InkWell( InkWell(
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0),
color: Colors.yellow, color: Colors.yellow,
child: Text( child: const Text(
'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
.open("sample://flutterFragmentPage"),
), ),
], onTap: () =>
), FlutterBoost.singleton.open('sample://flutterFragmentPage'),
),
],
),
), ),
), ),
); );
...@@ -501,23 +518,21 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> { ...@@ -501,23 +518,21 @@ 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: const Text('flutter_boost_example')),
title: Text('flutter_boost_example'),
),
body: Column( body: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
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,
...@@ -525,7 +540,7 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -525,7 +540,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,
...@@ -533,37 +548,40 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -533,37 +548,40 @@ class FragmentRouteWidget extends StatelessWidget {
Expanded(child: Container()), Expanded(child: Container()),
InkWell( InkWell(
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0),
color: Colors.yellow, color: Colors.yellow,
child: Text( child: const Text(
'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(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0),
color: Colors.yellow, color: Colors.yellow,
child: Text( child: const Text(
'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(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0), margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
color: Colors.yellow, color: Colors.yellow,
child: Text( child: const Text(
'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: () => onTap: () =>
FlutterBoost.singleton.open("sample://flutterFragmentPage"), FlutterBoost.singleton.open('sample://flutterFragmentPage'),
) )
], ],
), ),
...@@ -579,15 +597,8 @@ class PushWidget extends StatefulWidget { ...@@ -579,15 +597,8 @@ class PushWidget extends StatefulWidget {
class _PushWidgetState extends State<PushWidget> { class _PushWidgetState extends State<PushWidget> {
VoidCallback _backPressedListenerUnsub; VoidCallback _backPressedListenerUnsub;
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override @override
void didChangeDependencies() { void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies(); super.didChangeDependencies();
// if (_backPressedListenerUnsub == null) { // if (_backPressedListenerUnsub == null) {
...@@ -603,7 +614,6 @@ class _PushWidgetState extends State<PushWidget> { ...@@ -603,7 +614,6 @@ class _PushWidgetState extends State<PushWidget> {
@override @override
void dispose() { void dispose() {
// TODO: implement dispose
print('[XDEBUG] - PushWidget is disposing~'); print('[XDEBUG] - PushWidget is disposing~');
super.dispose(); super.dispose();
_backPressedListenerUnsub?.call(); _backPressedListenerUnsub?.call();
...@@ -611,6 +621,6 @@ class _PushWidgetState extends State<PushWidget> { ...@@ -611,6 +621,6 @@ class _PushWidgetState extends State<PushWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FlutterRouteWidget(message: "Pushed Widget"); return const FlutterRouteWidget(message: 'Pushed Widget');
} }
} }
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TestPage extends StatefulWidget { class TestPage extends StatefulWidget {
TestPage({Key key, this.title = "Input Test"}) : super(key: key); const TestPage({
Key key,
this.title = 'Input Test',
}) : super(key: key);
final String title; final String title;
...@@ -18,95 +21,82 @@ class _TestPageState extends State<TestPage> { ...@@ -18,95 +21,82 @@ class _TestPageState extends State<TestPage> {
}); });
} }
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: Text(widget.title)),
title: Text(widget.title),
),
body: SafeArea( body: SafeArea(
bottom: false, bottom: false,
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
Container( Container(
child: Text( child: const Text(
'You have pushed the button this many times:', 'You have pushed the button this many times:',
),
margin: const EdgeInsets.all(8.0),
alignment: Alignment.center,
), ),
margin: const EdgeInsets.all(8.0), Container(
alignment: Alignment.center, child: Text(
), '$_counter',
Container( style: Theme.of(context).textTheme.display1,
child: Text( ),
'$_counter', margin: const EdgeInsets.all(8.0),
style: Theme.of(context).textTheme.display1, alignment: Alignment.center,
), ),
margin: const EdgeInsets.all(8.0), Container(
alignment: Alignment.center, child: const TextField(minLines: 2, maxLines: 10),
), padding: const EdgeInsets.all(8.0),
Container(
child: TextField(
minLines: 2,
maxLines: 10,
), ),
padding: const EdgeInsets.all(8.0), TestTextField(),
), Container(
TestTextField(), child: Container(
Container( color: Colors.red,
child: Container( width: double.infinity,
color: Colors.red, height: 128.0,
width: double.infinity, ),
height: 128.0, padding: const EdgeInsets.all(8.0),
), ),
padding: const EdgeInsets.all(8.0), Container(
), child: Container(
Container( color: Colors.orange,
child: Container( width: double.infinity,
color: Colors.orange, height: 128.0,
width: double.infinity, ),
height: 128.0, padding: const EdgeInsets.all(8.0),
), ),
padding: const EdgeInsets.all(8.0), Container(
), child: Container(
Container( color: Colors.green,
child: Container( width: double.infinity,
color: Colors.green, height: 128.0,
width: double.infinity, ),
height: 128.0, padding: const EdgeInsets.all(8.0),
), ),
padding: const EdgeInsets.all(8.0), Container(
), child: Container(
Container( color: Colors.blue,
child: Container( width: double.infinity,
color: Colors.blue, height: 128.0,
width: double.infinity, ),
height: 128.0, padding: const EdgeInsets.all(8.0),
), ),
padding: const EdgeInsets.all(8.0), Container(
), child: Container(
Container( color: Colors.yellow,
child: Container( width: double.infinity,
color: Colors.yellow, height: 128.0,
width: double.infinity, ),
height: 128.0, padding: const EdgeInsets.all(8.0),
), ),
padding: const EdgeInsets.all(8.0), Container(
), child: const TextField(minLines: 2, maxLines: 10),
Container( padding: const EdgeInsets.all(8.0),
child: TextField(
minLines: 2,
maxLines: 10,
), ),
padding: const EdgeInsets.all(8.0), TestTextField(),
), ],
TestTextField(), ),
], ),
)),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter, onPressed: _incrementCounter,
tooltip: 'Increment', tooltip: 'Increment',
...@@ -123,22 +113,22 @@ class TestTextField extends StatefulWidget { ...@@ -123,22 +113,22 @@ class TestTextField extends StatefulWidget {
class _TestTextFieldState extends State<TestTextField> { class _TestTextFieldState extends State<TestTextField> {
FocusNode _node; FocusNode _node;
PersistentBottomSheetController _controller; PersistentBottomSheetController<dynamic> _controller;
@override @override
void initState() { void initState() {
// TODO: implement initState
super.initState(); super.initState();
_node = FocusNode(); _node = FocusNode();
_node.addListener(() { _node.addListener(() {
if (_node.hasFocus) { if (_node.hasFocus) {
print('showBottomSheet'); print('showBottomSheet');
_controller = Scaffold.of(context) _controller = Scaffold.of(context).showBottomSheet<dynamic>(
.showBottomSheet<dynamic>((BuildContext ctx) => Container( (BuildContext ctx) => Container(
width: double.infinity, width: double.infinity,
height: 36.0, height: 36.0,
color: Colors.deepPurple, color: Colors.deepPurple,
)); ),
);
} else { } else {
if (_controller != null) { if (_controller != null) {
//Navigator.of(context).pop(); //Navigator.of(context).pop();
......
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_boost_example/main.dart';
import '../lib/main.dart';
void main() { void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async { testWidgets('Verify Platform version', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(new MyApp()); await tester.pumpWidget(MyApp());
// Verify that platform version is retrieved. // Verify that platform version is retrieved.
expect( expect(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment