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;
......
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,24 +21,16 @@ class _TestPageState extends State<TestPage> { ...@@ -18,24 +21,16 @@ 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), margin: const EdgeInsets.all(8.0),
...@@ -50,10 +45,7 @@ class _TestPageState extends State<TestPage> { ...@@ -50,10 +45,7 @@ class _TestPageState extends State<TestPage> {
alignment: Alignment.center, alignment: Alignment.center,
), ),
Container( Container(
child: TextField( child: const TextField(minLines: 2, maxLines: 10),
minLines: 2,
maxLines: 10,
),
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
), ),
TestTextField(), TestTextField(),
...@@ -98,15 +90,13 @@ class _TestPageState extends State<TestPage> { ...@@ -98,15 +90,13 @@ class _TestPageState extends State<TestPage> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
), ),
Container( Container(
child: TextField( child: const TextField(minLines: 2, maxLines: 10),
minLines: 2,
maxLines: 10,
),
padding: const EdgeInsets.all(8.0), 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