You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'package:meta/meta.dart';
import'./equatable_utils.dart';
@immutableabstractclassEquatable {
finalMap props;
Equatable([this.props =const {}]);
@overridebooloperator==(Object other) =>identical(this, other) ||
other isEquatable&&
runtimeType == other.runtimeType &&equals(props.values.toList(), other.props.values.toList());
@overrideintget hashCode =>
runtimeType.hashCode ^mapPropsToHashCode(props.values.toList());
@overrideStringtoString() =>'$runtimeType${_propsToString()}';
String_propsToString() {
StringBuffer _result =StringBuffer();
if (props.isNotEmpty) {
_result.write(' {');
for (int i =0; i < props.length; i++) {
_result
..write(' ')
..write(props.keys.elementAt(i))
..write(': ')
..write(props.values.elementAt(i));
if (i != props.length -1) _result..write(',');
}
_result.write(' }');
}
return _result.toString();
}
}
Now you need to pass a Map to the super constructor, when the key is the String for show in toString() method, and the value, is the value to use to override == and hashcode
Based on our discussion on gitter, I am going to update toString to default to runtimeType because passing a map increases the complexity and is also tangential to the focus of the package.
Is your feature request related to a problem? Please describe.
If you have a
Credential
class:When you create a credential and print:
The output is:
Instance of 'Credentials'
In most cases you want to show the name of class, the property name and the value of each property, so you need to override
toString()
manually:And now the output is:
Describe the solution you'd like
Equatable accept a map instead of list.
Now you need to pass a
Map
to the super constructor, when the key is the String for show intoString()
method, and the value, is the value to use to override==
andhashcode
And now the output is:
Thanks 😀
The text was updated successfully, but these errors were encountered: