Skip to content

Commit

Permalink
example dartfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yohom committed Oct 16, 2018
1 parent 7e4451c commit 5d81a37
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ 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'
)
]
tabs: [
Tab(
text: 'Example 1: Navigation',
),
Tab(text: 'Example 2: Form')
],
),
),
body: TabBarView(
children: [
NavigationExample(),
FormExample()
]
)
FormExample(),
],
),
),
);
}
Expand All @@ -52,17 +49,17 @@ class NavigationExample extends StatelessWidget {
return Padding(
padding: EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10.0,),
TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,
style: DefaultTextStyle.of(context).style.copyWith(
fontStyle: FontStyle.italic
),
style: DefaultTextStyle.of(context)
.style
.copyWith(fontStyle: FontStyle.italic),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'What are you looking for?'
hintText: 'What are you looking for?',
),
),
suggestionsCallback: (pattern) async {
Expand All @@ -76,9 +73,11 @@ class NavigationExample extends StatelessWidget {
);
},
onSuggestionSelected: (suggestion) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ProductPage(product: suggestion)
));
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProductPage(product: suggestion),
),
);
},
),
],
Expand All @@ -93,7 +92,6 @@ class FormExample extends StatefulWidget {
}

class _FormExampleState extends State<FormExample> {

final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _typeAheadController = TextEditingController();

Expand All @@ -107,14 +105,10 @@ class _FormExampleState extends State<FormExample> {
padding: EdgeInsets.all(32.0),
child: Column(
children: <Widget>[
Text(
'What is your favorite city?'
),
Text('What is your favorite city?'),
TypeAheadFormField(
textFieldConfiguration: TextFieldConfiguration(
decoration: InputDecoration(
labelText: 'City'
),
decoration: InputDecoration(labelText: 'City'),
controller: this._typeAheadController,
),
suggestionsCallback: (pattern) {
Expand All @@ -138,15 +132,17 @@ class _FormExampleState extends State<FormExample> {
},
onSaved: (value) => this._selectedCity = value,
),
SizedBox(height: 10.0,),
SizedBox(
height: 10.0,
),
RaisedButton(
child: Text('Submit'),
onPressed: () {
if (this._formKey.currentState.validate()) {
this._formKey.currentState.save();
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Your Favorite City is ${this._selectedCity}')
));
content:
Text('Your Favorite City is ${this._selectedCity}')));
}
},
)
Expand All @@ -157,9 +153,7 @@ class _FormExampleState extends State<FormExample> {
}
}


class ProductPage extends StatelessWidget {

final Map<String, dynamic> product;

ProductPage({this.product});
Expand All @@ -186,22 +180,17 @@ class ProductPage extends StatelessWidget {
}
}


class BackendService {
static Future<List> getSuggestions(String query) async {
await Future.delayed(Duration(seconds: 1));

return List.generate(3, (index) {
return {
'name': query + index.toString(),
'price': Random().nextInt(100)
};
return {'name': query + index.toString(), 'price': Random().nextInt(100)};
});
}
}

class CitiesService {

static final cities = [
'Beirut',
'Damascus',
Expand All @@ -219,7 +208,8 @@ class CitiesService {
final cities = CitiesService.cities;

cities.sort((a, b) {
return CitiesService._distance(query, a) - CitiesService._distance(query, b);
return CitiesService._distance(query, a) -
CitiesService._distance(query, b);
});

return cities.take(4).toList();
Expand Down

0 comments on commit 5d81a37

Please sign in to comment.