From 28d0b697b71983e254a956ad883330ec16de836d Mon Sep 17 00:00:00 2001 From: yohom <382146139@qq.com> Date: Tue, 16 Oct 2018 17:01:08 +0800 Subject: [PATCH] update example for #9 --- example/lib/main.dart | 75 ++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 7edcafba..693f5491 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -19,31 +19,42 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { - return DefaultTabController( - length: 2, - child: Scaffold( - appBar: AppBar( - title: TabBar( - tabs: [ - Tab( - text: 'Example 1: Navigation', - ), - Tab(text: 'Example 2: Form') + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () => FocusScope.of(context).requestFocus(FocusNode()), + child: DefaultTabController( + length: 2, + child: Scaffold( + appBar: AppBar( + title: TabBar( + tabs: [ + Tab( + text: 'Example 1: Navigation', + ), + Tab(text: 'Example 2: Form') + ], + ), + ), + body: TabBarView( + children: [ + NavigationExample(), + FormExample(), ], ), ), - body: TabBarView( - children: [ - NavigationExample(), - FormExample(), - ], - ), ), ); } } -class NavigationExample extends StatelessWidget { +class NavigationExample extends StatefulWidget { + @override + _NavigationExampleState createState() => _NavigationExampleState(); +} + +class _NavigationExampleState extends State { + AxisDirection _direction = AxisDirection.down; + @override Widget build(BuildContext context) { return Padding( @@ -79,6 +90,19 @@ class NavigationExample extends StatelessWidget { ), ); }, + direction: _direction, + ), + FlatButton( + onPressed: () { + setState(() { + _direction = _direction == AxisDirection.down + ? AxisDirection.up + : AxisDirection.down; + }); + }, + child: Text( + 'toggle direction to ${_direction == AxisDirection.down ? AxisDirection.up : AxisDirection.down}', + ), ), ], ), @@ -96,6 +120,7 @@ class _FormExampleState extends State { final TextEditingController _typeAheadController = TextEditingController(); String _selectedCity; + AxisDirection _direction = AxisDirection.down; @override Widget build(BuildContext context) { @@ -104,6 +129,7 @@ class _FormExampleState extends State { child: Padding( padding: EdgeInsets.all(32.0), child: Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ Text('What is your favorite city?'), TypeAheadFormField( @@ -131,6 +157,7 @@ class _FormExampleState extends State { } }, onSaved: (value) => this._selectedCity = value, + direction: _direction, ), SizedBox( height: 10.0, @@ -145,7 +172,19 @@ class _FormExampleState extends State { Text('Your Favorite City is ${this._selectedCity}'))); } }, - ) + ), + FlatButton( + onPressed: () { + setState(() { + _direction = _direction == AxisDirection.down + ? AxisDirection.up + : AxisDirection.down; + }); + }, + child: Text( + 'toggle direction to ${_direction == AxisDirection.down ? AxisDirection.up : AxisDirection.down}', + ), + ), ], ), ),