Skip to content

Instantly share code, notes, and snippets.

@JoeCodeswell
Last active July 26, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeCodeswell/34f5fca2d4e3df65155189b3be033da3 to your computer and use it in GitHub Desktop.
Save JoeCodeswell/34f5fca2d4e3df65155189b3be033da3 to your computer and use it in GitHub Desktop.
DartDataTableExp1
void main() {
// DartDataTableExp1
// https://gist.github.com/JoeCodeswell/34f5fca2d4e3df65155189b3be033da3
// https://dartpad.dev/34f5fca2d4e3df65155189b3be033da3
JoesDataList jdl = JoesDataList();
print(jdl.listOfDataItems[0].name); // Sarah
print(' ');
// jdl.Map(); // The method 'Map' isn't defined for the type 'JoesDataList' - line 4
List<Avengers> avengers = Avengers.getAvengers();
// No toList()
var rowsColon = avengers.map(
(avenger) => [avenger.name, avenger.weapon]
);
print(rowsColon.runtimeType); // MappedListIterable<Avengers, List<String>>
print(' ');
print(rowsColon);
// ([Captain America, Shield], [Thor, Mjolnir], [Spiderman, Web Shooters], [Doctor Strange , Eye Of Agamotto])
print(' ');
// print(rowsColon.forEach( (itm) => { 'name': itm[0], 'weapon': itm[1] } ) );
// `forEach` This expression has a type of 'void' so its value can't be used
rowsColon.forEach( (itm) => print( { 'name': itm[0], 'weapon': itm[1] } ) );
/*
{name: Captain America, weapon: Shield}
{name: Thor, weapon: Mjolnir}
{name: Spiderman, weapon: Web Shooters}
{name: Doctor Strange , weapon: Eye Of Agamotto}
*/
print(' ');
rowsColon.forEach( (itm) => print([itm[0], itm[1]]) );
/*
[Captain America, Shield]
[Thor, Mjolnir]
[Spiderman, Web Shooters]
[Doctor Strange , Eye Of Agamotto]
*/
print(' ');
// with toList()
var rowsColon0 = avengers.map(
(avenger) => [avenger.name, avenger.weapon]
).toList();
print(rowsColon0.runtimeType); // JSArray<List<String>>
print(' ');
print(rowsColon0);
// [[Captain America, Shield], [Thor, Mjolnir], [Spiderman, Web Shooters], [Doctor Strange , Eye Of Agamotto]]
print(' ');
print(rowsColon0[0][0]); // Captain America
print(rowsColon0[0][1]); // Shield
print(' ');
print(rowsColon0[1][0]); // Thor
print(rowsColon0[1][1]); // Mjolnir
print(' ');
}
class Avengers {
String name;
String weapon;
Avengers({this.name, this.weapon});
static List<Avengers> getAvengers() {
return <Avengers>[
Avengers (name: "Captain America", weapon: "Shield"),
Avengers (name: "Thor", weapon: "Mjolnir"),
Avengers (name: "Spiderman", weapon: "Web Shooters"),
Avengers (name: "Doctor Strange ", weapon: "Eye Of Agamotto"),
]; // <Avengers>[]
}
}
class JdataItem{
String name;
int age;
String title;
JdataItem(this.name,this.age,this.title);
}
class JoesDataList{
List<JdataItem> listOfDataItems = [
JdataItem('Sarah', 19, 'Student',),
JdataItem('Janine', 43, 'Professor',),
JdataItem('William', 27, 'Associate Professor',),
JdataItem('Frances', 37, 'Student',),
JdataItem('Maxine', 21, 'Student',),
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment