Created
August 10, 2019 09:05
-
-
Save juliuscanute/e484a55e9c3d77d1bd3a50639abd4a97 to your computer and use it in GitHub Desktop.
[Creating a ListView] #dart #flutter #listview
This file contains hidden or 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 T1 extends StatelessWidget { | |
final T1 v1; | |
const $1({ | |
Key key, | |
@required this.v1, | |
}) : assert( v1 != null ), | |
super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Widget(); | |
} | |
} |
This file contains hidden or 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 CategoryRoute extends StatelessWidget { | |
const CategoryRoute(); | |
static const _categoryNames = <String>[ | |
'Length', | |
'Area', | |
'Volume', | |
'Mass', | |
'Time', | |
'Digital Storage', | |
'Energy', | |
'Currency', | |
]; | |
static const _baseColors = <Color>[ | |
Colors.teal, | |
Colors.orange, | |
Colors.pinkAccent, | |
Colors.blueAccent, | |
Colors.yellow, | |
Colors.greenAccent, | |
Colors.purpleAccent, | |
Colors.red, | |
]; | |
/// Makes the correct number of rows for the list view. | |
/// | |
/// For portrait, we construct a [ListView] from the list of category widgets. | |
Widget _buildCategoryWidgets(List<Widget> categories) { | |
return ListView.builder( | |
itemBuilder: (BuildContext context, int index) => categories[index], | |
itemCount: categories.length, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final categories = <Category>[]; | |
for (var i = 0; i < _categoryNames.length; i++) { | |
categories.add(Category( | |
name: _categoryNames[i], | |
color: _baseColors[i], | |
iconLocation: Icons.cake, | |
)); | |
} | |
final listView = Container( | |
color: _backgroundColor, | |
padding: EdgeInsets.symmetric(horizontal: 8.0), | |
child: _buildCategoryWidgets(categories), | |
); | |
final appBar = AppBar( | |
elevation: 0.0, | |
title: Text( | |
'Unit Converter', | |
style: TextStyle( | |
color: Colors.black, | |
fontSize: 30.0, | |
), | |
), | |
centerTitle: true, | |
backgroundColor: _backgroundColor, | |
); | |
return Scaffold( | |
appBar: appBar, | |
body: listView, | |
); | |
} | |
} |
This file contains hidden or 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 $1 extends StatelessWidget { | |
const $1(); | |
static const _listValues1 = <String>[ | |
'v1', | |
'v2', | |
'v3', | |
]; | |
_buildP1Widgets(List<Widget> p1) { | |
return ListView.builder( | |
itemBuilder: (BuildContext context, int index) => p1[index], | |
itemCount: p1.length, | |
); | |
} | |
Widget build(BuildContext context) { | |
final p1 = <T1>[]; | |
for (var i = 0; i < _listValues1.length; i++) { | |
p1.add(T1(value: _listValues1[i])); | |
} | |
return Container( | |
padding: EdgeInsets.symmetric(horizontal: 8.0), | |
child: _buildP1Widgets(p1), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment