mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-19 01:03:45 +02:00
Merge pull request #8 from Iconica-Development/hotfix/name-check-isempty
firstname, lastname check not empty
This commit is contained in:
commit
898c2f9092
2 changed files with 12 additions and 4 deletions
|
@ -21,7 +21,8 @@ class User {
|
|||
});
|
||||
|
||||
String get displayName => '${firstName ?? ''} ${lastName ?? ''}';
|
||||
String get initials => '${firstName?[0] ?? ''}${lastName?[0] ?? ''}';
|
||||
String get initials =>
|
||||
'${(firstName?.isNotEmpty ?? false) ? firstName![0] : ''}${(lastName?.isNotEmpty ?? false) ? lastName![0] : ''}';
|
||||
|
||||
factory User.fromMap(Map<String, dynamic> data) => User(
|
||||
firstName: data['first_name'],
|
||||
|
|
|
@ -58,9 +58,16 @@ class Avatar extends StatelessWidget {
|
|||
}
|
||||
|
||||
Color _generateColorWithIntials(String? firstName, String? lastName) {
|
||||
var uniqueInitialId = (firstName?.toLowerCase().codeUnitAt(0) ?? 0) +
|
||||
(lastName?.toLowerCase().codeUnitAt(0) ?? 0);
|
||||
var idFirstName = 0;
|
||||
var idLastName = 0;
|
||||
if (firstName?.isNotEmpty ?? false) {
|
||||
idFirstName = firstName!.toLowerCase().codeUnitAt(0);
|
||||
}
|
||||
if (lastName?.isNotEmpty ?? false) {
|
||||
idLastName = lastName!.toLowerCase().codeUnitAt(0);
|
||||
}
|
||||
|
||||
return Colors.primaries[uniqueInitialId % Colors.primaries.length];
|
||||
return Colors
|
||||
.primaries[(idFirstName + idLastName) % Colors.primaries.length];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue