Skip to content

Instantly share code, notes, and snippets.

@LokieVikky
Created May 30, 2023 02:22
Show Gist options
  • Save LokieVikky/417bfc44d6297357972cc53143148af7 to your computer and use it in GitHub Desktop.
Save LokieVikky/417bfc44d6297357972cc53143148af7 to your computer and use it in GitHub Desktop.
enum EnumValue {
value1,
value2,
value3,
value4,
}
void main() {
// List
// List list = [];
// List<String> listOfNames = ['Deva', 'Guna', 'Gopi', 'Joel'];
// List<String> listOfNames2 = ['Deva', 'Guna', 'Gopi', 'Joel'];
// // Adding
// listOfNames.add('Lokesh');
// // Adding Multiple items
// listOfNames.addAll(listOfNames2);
// // retriving with index
// String value = listOfNames[2];
// List<String> searchedValues = listOfNames.where((String value) {
// if (value == 'Joel') {
// return true;
// } else {
// return false;
// }
// }).toList();
// print(searchedValues);
// String searchValue = listOfNames.singleWhere((value) {
// return value == 'Joel';
// });
// print(searchValue);
// print(listOfNames.indexOf('Joel'));
// print(listOfNames.indexWhere((value) {
// return value == 'Joel';
// }));
// print(listOfNames.any((value) {
// return value == 'Joel';
// }));
// listOfNames.insert(0, 'Mani');
// listOfNames.remove('Joel');
// listOfNames.removeAt(0);
// listOfNames.removeRange(0, 2);
// listOfNames.removeWhere((value) {
// return value == 'Joel';
// });
// listOfNames.removeWhere((value) => value == 'Joel');
// List<int> numbers = [0, 1, 2, 3, 4, 5];
// print(numbers);
// List<String> convertedValue =
// numbers.map((value) => value.toString()).toList();
// print(convertedValue);
// print(listOfNames.asMap());
// // Map
// Map map = {};
// Map<String, dynamic> mapOfString = {
// 'key1': 'value1',
// 'key2': 'value2',
// 'key3': 'value3',
// };
// print(mapOfString['key1']);
// // adding values to map
// mapOfString['key4'] = 'value4';
// mapOfString['key4'] = 'value4';
// mapOfString.map((key, value) {
// print(key);
// print(value);
// return MapEntry(key, value);
// });
// // removing values from map
// mapOfString.remove('key2');
// mapOfString.putIfAbsent('key3', () => 'value');
// mapOfString.putIfAbsent('key3', () {
// return 'value';
// });
// EnumValue enumValue = EnumValue.value1;
// switch (enumValue) {
// case EnumValue.value1:
// break;
// case EnumValue.value2:
// break;
// case EnumValue.value3:
// break;
// case EnumValue.value4:
// break;
// default:
// break;
// }
User user = User(1,'name',12);
User user1 = User.fromJson({
'id':2,
'name': 'name',
'age':3
});
user.age = 23;
}
class User {
int id;
String name;
int age;
User(this.id, this.name, this.age);
factory User.fromJson(Map json) {
return User(
json['id'],
json['name'],
json['age'],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment