Skip to content

Instantly share code, notes, and snippets.

@nikli2009
Created July 5, 2019 11:29
Show Gist options
  • Save nikli2009/b6ea7254e1bc98009f408d5b723858f8 to your computer and use it in GitHub Desktop.
Save nikli2009/b6ea7254e1bc98009f408d5b723858f8 to your computer and use it in GitHub Desktop.
Dart Map
void main() {
// handle data
// use Class is kind of overkill from Design Perspective
var user = {
'name': 'Nikk.Li',
'age': 28,
'height': 171.0,
'weight': 63,
'children': null
};
var carList = [
{
'model': 'benz',
'year': 2019,
'currency': 'CNY',
'price': 400000.00
},
{
'model': 'honda',
'year': 2020,
'currency': 'CNY',
'price': 150000.00
}
];
print(carList);
print(user);
// Map => containsKey
print(''.padLeft(12, '-'));
print('user Contains Key: age');
print(user.containsKey('age'));
print('user Contains Key: job');
print(user.containsKey('job'));
// Map => forEach
print(''.padLeft(12, '-'));
user.forEach((k, value){
print('user forEach $k - $value');
});
// Map => remove (at key)
print(''.padLeft(12, '-'));
user.remove('age');
print(user); // {name: Nikk.Li, height: 171, weight: 63, children: null}
// Map => keys
print(''.padLeft(12, '-'));
print(user.keys);
// Map => values
print(''.padLeft(12, '-'));
print(user.values);
// Map => length
print(''.padLeft(12, '-'));
print(user.length);
// Map => addAll
print(''.padLeft(12, '-'));
user.addAll({
'location': 'China'
});
print(user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment