Created
November 2, 2023 12:30
-
-
Save Devlonoah/5c06d26627e843ee77bc703b42440931 to your computer and use it in GitHub Desktop.
Equality using equatable with Set
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
import 'package:equatable/equatable.dart'; | |
void main() { | |
Set<InfoModel> info = {}; | |
for (var data in infoList) { | |
info.add(data); | |
} | |
print("All unique info saved: $info"); | |
} | |
var infoList = [ | |
InfoModel("John", 23), | |
InfoModel("John", 23), | |
InfoModel("Jane", 25), | |
InfoModel("John", 23), | |
]; | |
class InfoModel extends Equatable { | |
final String name; | |
final int age; | |
InfoModel(this.name, this.age); | |
@override | |
List<Object> get props => [name, age]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment