Created
June 18, 2023 20:24
-
-
Save guhakashyap/b1633d9851eea0d013c0710d00f8af2b to your computer and use it in GitHub Desktop.
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 Test { | |
bool? a; | |
bool? b; | |
String? ex; | |
String? yz; | |
Test({ | |
this.a, | |
this.b, | |
this.ex, | |
this.yz, | |
}); | |
Map<String, dynamic> toJson() => | |
{ | |
"a": a, | |
"b": b, | |
"ex": ex, | |
"yz": yz, | |
}; | |
Test copy({bool? a, bool? b, String? ex, String? yz}){ | |
return Test( | |
a : a ?? this.a, | |
b : b ?? this.b, | |
ex : ex ?? this.ex, | |
yz : yz ?? this.yz, | |
); | |
} | |
} | |
void main() { | |
Test a = Test( | |
a : true, | |
b : false, | |
ex : "S001", | |
yz : "plus" | |
); | |
Test b = Test( | |
a : false, | |
b : true, | |
ex : "S001", | |
yz : "plus" | |
); | |
Test c = Test( | |
a : true, | |
b : true, | |
ex : "S001", | |
yz : "plus" | |
); | |
Test d = Test( | |
a : false, | |
b : false, | |
ex : "S001", | |
yz : "plus" | |
); | |
Test z = a.copy(); // we want to remove an object with attributes matching 'a' from the list | |
List<Test> testList = [a, b, c, d]; | |
for(var item in testList){ print(item.toJson()); } // [a, b, c, d] | |
var result = testList.remove(a.copy()); | |
print(result); | |
for(var item in testList){ print(item.toJson()); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment