Skip to content

Instantly share code, notes, and snippets.

@guhakashyap
Created June 18, 2023 20:24
Show Gist options
  • Save guhakashyap/b1633d9851eea0d013c0710d00f8af2b to your computer and use it in GitHub Desktop.
Save guhakashyap/b1633d9851eea0d013c0710d00f8af2b to your computer and use it in GitHub Desktop.
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