Flutter smoke dev maps¶
Smoke Test App with maps¶
maps smoke app¶
Screencasts¶
tc74 Create nomnom:
flutter create nomnom flutter run
tc87 Codebase clear comments lib/main.dart and change name on line 13
tc188 Remove boilderplate layout and add “Hello World”:
body: new Center( child: new Text('hello world') ),
tc211 Take out _incrementCounter
tc229 Create dummy test data for list view:
List<String> _places = <String>[]; @override initState() { super.initState(); _places = new List.generate(100, (i) => 'Restauant $i');
tc324 Put list in view:
body: new Center( child: new ListView( children: _places.map((place) => Text (place)).toList(), )),
tc401 Add google places API:
cp ../src/places.dart ./lib/ cp ../src/key.dart ./lib/
tc519 Open pubspec.yaml add to line 8:
http: ^0.11.3
tc586 Run command line:
dart lib/places.dart
tc628 Parse json in a nice way (code is commented out in places.dart file)into streams.
tc761 Return stream to flutter app by using:
Future<Stream<Place>>
tc800 In file lib/main.dart make function:
import 'places.dart'; ... List<Place> _places = <Place>[]; ... @override initState() { super.initState(); listenForPlaces(); } ... listenForPlaces() async { var stream = await getPlaces(33.9850, -118.4695); stream.listen( (place) => setState[ () => _places.add(place)) ); } ... children: _places.map((place) => new Text(place.name)).toList(), ...
tc984 Should get a ‘non-pretty’ list
tc1000 Make it pretty
tc1009 In main.dart add new widget PlaceWidget:
class PlaceWidget extends StatelessWidget { final Place _place; PlaceWidget(this._place); @override Widget build(BuildContext context) { // TODO: implement build return new ListTile( title: new Text(_place.name), ); // ListTile } }
tc1048 Override the build widget:
children: _places.map((place) => new PlaceWidget(place)).toList(),
tc1116 Add subtitle:
class PlaceWidget extends StatelessWidget { final Place _place; PlaceWidget(this._place); @override Widget build(BuildContext context) { // TODO: implement build return new ListTile( title: new Text(_place.name), subtitle: new Text(_place.address), ); // ListTile } }
tc1138 Add leading:
class PlaceWidget extends StatelessWidget { final Place _place; PlaceWidget(this._place); @override Widget build(BuildContext context) { // TODO: implement build return new ListTile( leading: new CircleAvatar( child: new Text(_place.rating.toString()), backgroundColor: Colors.green, ), // CircleAvatar title: new Text(_place.name), subtitle: new Text(_place.address), ); // ListTile } }
tc1197: Update backgroundColor based on Rating using interpolation:
class PlaceWidget extends StatelessWidget { final Place _place; PlaceWidget(this._place); Color getColor(double rating) { return Color.lerp(Colors.red, Colors.green, rating/5); } @override Widget build(BuildContext context) { // TODO: implement build return new ListTile( leading: new CircleAvatar( child: new Text(_place.rating.toString()), backgroundColor: getColor(_place.rating), ), // CircleAvatar title: new Text(_place.name), subtitle: new Text(_place.address), ); // ListTile } }
tc1293 Put in Swipe Right to Like, Left to Remove using Dismissible:
class PlaceWidget extends StatelessWidget { final Place _place; PlaceWidget(this._place); Color getColor(double rating) { return Color.lerp(Colors.red, Colors.green, rating/5); } @override Widget build(BuildContext context) { // TODO: implement build return new Dismissible( key: new Key(_place.name), background: new Container(color: Colors.green), secondaryBackground: new Container(color: Colors.red), leading: new CircleAvatar( child: new Text(_place.rating.toString()), backgroundColor: getColor(_place.rating), ), // CircleAvatar title: new Text(_place.name), subtitle: new Text(_place.address), ); // ListTile } }
tc1415 Add text to swipe feedback:
onDismissed: (direction) { direction == DismissDirection.endToStart ? Scaffold.of(context).showSnackBar( new SnackBar(content: new Text('I Like'))) : print('No Like'); },tc1609 Show some of the render debugging performance.
References¶
- Tutorial via “Let’s live code in Flutter (DartConf 2018)” see youtube-flutter-maps-tutorial
- Github source for tutorial youtube-flutter-maps-github