Here is a class with private fields and the constructor :
class User {
final String _id;
final String _username;
final String _photoUrl;
final String _bio;
final String _city;
final Map<String, dynamic> _favorite;
const User({@required String id,
@required String username,
String photoUrl,
String bio,
String city,
Map<String, dynamic> favorite
})
: this._id = id,
this._username = username,
this._photoUrl = photoUrl,
this._bio = bio,
this._city = city,
this._favorite = favorite ?? const{};
User copyWith({String id, String username, String photoUrl, String bio, String city, Map<String, dynamic> favorite}){
return User(
id: id ?? this._id,
username: username ?? this._username,
photoUrl: photoUrl ?? this._photoUrl,
bio: bio ?? this._bio,
city: city ?? this._city,
favorite: favorite ?? this._favorite,
);
}
String get id => _id;
String get username => _username;
String get photoUrl => _photoUrl;
String get bio => _bio;
String get city => _city;
Map<String, dynamic> get favorite => _favorite;
@override
int get hashCode => _id.hashCode ^ _username.hashCode ^ _photoUrl.hashCode ^ _city.hashCode ^ _bio.hashCode ^ _favorite.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is User &&
runtimeType == other.runtimeType &&
_id == other._id;
@override
String toString(){
return 'User { _id : $_id, _username : $_username, _photoUrl : $_photoUrl, _bio : $_bio, _city : $_city, _favorite : $_favorite';
}
When I use the constructor to create an instance of the class, and that I observe it with the debugger, I feel like I see a duplication of each variable : the private field and the argument. Is that normal ?
