Commit 4871b571 authored by AlexVincent525's avatar AlexVincent525

🎨 Improve code in swift example.

parent 9fea4af0
...@@ -16,17 +16,22 @@ class _MyAppState extends State<MyApp> { ...@@ -16,17 +16,22 @@ 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(),
'tab': (pageName, params, _) => TabRouteWidget(), 'second': (String pageName, Map<String, dynamic> params, String _) =>
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params), SecondRouteWidget(),
'tab': (String pageName, Map<String, dynamic> params, String _) =>
TabRouteWidget(),
'flutterFragment':
(String pageName, Map<String, dynamic> params, String _) =>
FragmentRouteWidget(params),
///可以在native层通过 getContainerParams 来传递参数 ///可以在native层通过 getContainerParams 来传递参数
'flutterPage': (pageName, params, _) { 'flutterPage': (String pageName, Map<String, dynamic> params, String _) {
print("flutterPage params:$params"); print('flutterPage params:$params');
return FlutterRouteWidget(); return const FlutterRouteWidget();
}, },
}); });
} }
...@@ -34,12 +39,17 @@ class _MyAppState extends State<MyApp> { ...@@ -34,12 +39,17 @@ class _MyAppState extends State<MyApp> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
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(),
);
} }
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> _,
) {}
} }
This diff is collapsed.
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,100 +21,87 @@ class _TestPageState extends State<TestPage> { ...@@ -18,100 +21,87 @@ 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',
child: Icon(Icons.add), child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods. ),
); );
} }
} }
...@@ -123,25 +113,24 @@ class TestTextField extends StatefulWidget { ...@@ -123,25 +113,24 @@ 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();
print('closeBottomSheet'); print('closeBottomSheet');
_controller.close(); _controller.close();
} }
......
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