Skip to content

Commit

Permalink
update example for AbdulRahmanAlHamali#9
Browse files Browse the repository at this point in the history
  • Loading branch information
yohom committed Oct 16, 2018
1 parent 5d81a37 commit 28d0b69
Showing 1 changed file with 57 additions and 18 deletions.
75 changes: 57 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationExample> {
AxisDirection _direction = AxisDirection.down;

@override
Widget build(BuildContext context) {
return Padding(
Expand Down Expand Up @@ -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}',
),
),
],
),
Expand All @@ -96,6 +120,7 @@ class _FormExampleState extends State<FormExample> {
final TextEditingController _typeAheadController = TextEditingController();

String _selectedCity;
AxisDirection _direction = AxisDirection.down;

@override
Widget build(BuildContext context) {
Expand All @@ -104,6 +129,7 @@ class _FormExampleState extends State<FormExample> {
child: Padding(
padding: EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('What is your favorite city?'),
TypeAheadFormField(
Expand Down Expand Up @@ -131,6 +157,7 @@ class _FormExampleState extends State<FormExample> {
}
},
onSaved: (value) => this._selectedCity = value,
direction: _direction,
),
SizedBox(
height: 10.0,
Expand All @@ -145,7 +172,19 @@ class _FormExampleState extends State<FormExample> {
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}',
),
),
],
),
),
Expand Down

0 comments on commit 28d0b69

Please sign in to comment.