This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
itemBuilder: (context, index) { | |
final Map currency = _currencies[index]; | |
final MaterialColor color = _colors[index % _colors.length]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget _getListViewWidget() { | |
// We want the ListView to have the flexibility to expand to fill the | |
// available space in the vertical axis | |
return new Flexible( | |
child: new ListView.builder( | |
// The number of items to show | |
itemCount: _currencies.length, | |
// Callback that should return ListView children | |
// The index parameter = 0...(itemCount-1) | |
itemBuilder: (context, index) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget _getAppTitleWidget() { | |
return new Text( | |
'Cryptocurrencies', | |
style: new TextStyle( | |
color: Colors.white, | |
fontWeight: FontWeight.bold, | |
fontSize: 24.0), | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget _buildBody() { | |
return new Container( | |
// A top margin of 56.0. A left and right margin of 8.0. And a bottom margin of 0.0. | |
margin: const EdgeInsets.fromLTRB(8.0, 56.0, 8.0, 0.0), | |
child: new Column( | |
// A column widget can have several widgets that are placed in a top down fashion | |
children: <Widget>[ | |
_getAppTitleWidget(), | |
_getListViewWidget() | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
body: _buildBody(), | |
backgroundColor: Colors.blue, | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CryptoListWidget extends StatelessWidget { | |
// This is a list of material colors. Feel free to add more colors, it won't break the code | |
final List<MaterialColor> _colors = [Colors.blue, Colors.indigo, Colors.red]; | |
// The underscore before a variable name marks it as a private variable | |
final List _currencies; | |
// This is a constructor in Dart. We are assigning the value passed to the constructor | |
// to the _currencies variable | |
CryptoListWidget(this._currencies); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async { | |
// Bad practice alert :). You should ideally show the UI, and probably a progress view, | |
// then when the requests completes, update the UI to show the data. | |
List currencies = await getCurrencies(); | |
print(currencies); | |
runApp(new MaterialApp( | |
home: new CryptoListWidget(currencies), | |
)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'package:http/http.dart' as http; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Since we are using await within the main function, we have to make it asynchronous too | |
void main() async { | |
// Testing the getCurrencies function | |
// We wait for the currency data to arrive | |
List currencies = await getCurrencies(); | |
// Before printing it to the Console | |
print(currencies); | |
runApp(new MaterialApp( | |
home: new Center( |