Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Trim avatar identity component API

Neeraj Gupta31346705d5fc
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart
index cb2453cc42..ad3803aa5c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart
@@ -39,9 +39,9 @@ class AddedByWidget extends StatelessWidget {
}
final colors = context.componentColors;
final avatar = identity.role == AvatarIdentityRole.standard
- ? AvatarComponent.identity(
+ ? AvatarComponent.seeded(
initials: identity.initial,
- identityKey: identity.key,
+ seed: avatarSeedForIdentity(identity.key),
size: AvatarComponentSize.defaultSize,
)
: AvatarComponent(
diff --git a/mobile/packages/ente_components/lib/components/avatar_component.dart b/mobile/packages/ente_components/lib/components/avatar_component.dart
index ab0c70b0ff..45e99985c7 100644
--- a/mobile/packages/ente_components/lib/components/avatar_component.dart
+++ b/mobile/packages/ente_components/lib/components/avatar_component.dart
@@ -146,18 +146,6 @@ class AvatarComponent extends StatelessWidget {
this.seed,
this.semanticLabel,
}) : image = null,
- identityKey = null,
- icon = null;
-
- const AvatarComponent.identity({
- super.key,
- required this.initials,
- required this.identityKey,
- this.size = AvatarComponentSize.defaultSize,
- this.semanticLabel,
- }) : image = null,
- color = AvatarComponentColor.yellow,
- seed = null,
icon = null;
const AvatarComponent.image({
@@ -167,7 +155,6 @@ class AvatarComponent extends StatelessWidget {
this.semanticLabel,
}) : initials = '',
color = AvatarComponentColor.yellow,
- identityKey = null,
seed = null,
icon = null;
@@ -179,7 +166,6 @@ class AvatarComponent extends StatelessWidget {
}) : initials = '',
image = null,
color = AvatarComponentColor.yellow,
- identityKey = null,
seed = null;
const AvatarComponent.seeded({
@@ -190,13 +176,11 @@ class AvatarComponent extends StatelessWidget {
this.semanticLabel,
}) : image = null,
color = AvatarComponentColor.yellow,
- identityKey = null,
icon = null;
final String initials;
final AvatarComponentSize size;
final AvatarComponentColor color;
- final String? identityKey;
final int? seed;
final ImageProvider? image;
final Widget? icon;
@@ -285,9 +269,6 @@ class AvatarComponent extends StatelessWidget {
Color _backgroundColor(BuildContext context) {
final colors = context.componentColors;
- if (identityKey != null) {
- return avatarColorForIdentity(context, identityKey!);
- }
if (seed != null) {
final palette = Theme.of(context).brightness == Brightness.dark
? avatarDark
diff --git a/mobile/packages/ente_components/test/components/avatar_test.dart b/mobile/packages/ente_components/test/components/avatar_test.dart
index 8600616897..84fa7f6312 100644
--- a/mobile/packages/ente_components/test/components/avatar_test.dart
+++ b/mobile/packages/ente_components/test/components/avatar_test.dart
@@ -94,39 +94,33 @@ void main() {
},
);
- testWidgets('identity avatars use the theme palette at a stable index', (
+ testWidgets('identity colors use the theme palette at a stable index', (
tester,
) async {
const identityKey = '[email protected]';
final paletteIndex =
avatarSeedForIdentity(identityKey) % avatarLight.length;
-
- await tester.pumpWidget(
- _wrap(
- const AvatarComponent.identity(initials: 'A', identityKey: identityKey),
- ),
- );
- expect(_avatarBackground(tester), avatarLight[paletteIndex]);
-
- await tester.pumpWidget(
- _wrap(
- const AvatarComponent.identity(initials: 'A', identityKey: identityKey),
- theme: ComponentTheme.darkTheme(),
- ),
- );
- expect(_avatarBackground(tester), avatarDark[paletteIndex]);
+ for (final (theme, palette) in [
+ (ComponentTheme.lightTheme(), avatarLight),
+ (ComponentTheme.darkTheme(), avatarDark),
+ ]) {
+ late Color color;
+ await tester.pumpWidget(
+ _wrap(
+ Builder(
+ builder: (context) {
+ color = avatarColorForIdentity(context, identityKey);
+ return const SizedBox.shrink();
+ },
+ ),
+ theme: theme,
+ ),
+ );
+ expect(color, palette[paletteIndex]);
+ }
});
}
-Color? _avatarBackground(WidgetTester tester) {
- final avatar = tester.widget<DecoratedBox>(
- find
- .ancestor(of: find.text('A'), matching: find.byType(DecoratedBox))
- .first,
- );
- return (avatar.decoration as BoxDecoration).color;
-}
-
Widget _wrap(Widget child, {ThemeData? theme}) {
return MaterialApp(
theme: theme ?? ComponentTheme.lightTheme(),