π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Update avatar sizes from Figma
ashilknce05ae606657
diff --git a/mobile/apps/photos/lib/ui/collections/album/row_item.dart b/mobile/apps/photos/lib/ui/collections/album/row_item.dartindex 92687353da..7e7d0c5084 100644--- a/mobile/apps/photos/lib/ui/collections/album/row_item.dart+++ b/mobile/apps/photos/lib/ui/collections/album/row_item.dart@@ -124,9 +124,7 @@ class AlbumRowItemWidget extends StatelessWidget {Container(decoration: BoxDecoration(color: componentColors.specialScrim- .withValues(- alpha: 0.4,- ),+ .withValues(alpha: 0.4),),),],@@ -157,7 +155,7 @@ class AlbumRowItemWidget extends StatelessWidget {borderRadius: BorderRadius.circular(40),),child: SizedBox(- height: getAvatarSize(AvatarType.small),+ height: getAvatarSize(AvatarType.xs),child: _AlbumRowSharePillContent(sharees: c.getSharees(),trailingWidget: linkIcon,@@ -202,7 +200,7 @@ class AlbumRowItemWidget extends StatelessWidget {transitionOnUserGestures: true,child: SizedBox.square(dimension:- getAvatarSize(AvatarType.small) ++ getAvatarSize(AvatarType.xs) +_sharedAvatarStrokeWidth * 2,child: Stack(alignment: Alignment.center,@@ -210,7 +208,7 @@ class AlbumRowItemWidget extends StatelessWidget {UserAvatarWidget(c.owner,thumbnailView: true,- type: AvatarType.small,+ type: AvatarType.xs,),Positioned.fill(child: IgnorePointer(@@ -263,10 +261,9 @@ class AlbumRowItemWidget extends StatelessWidget {.getCachedFileCount(c);}if (cachedCount != null && cachedCount > 0) {- final String textCount = AppLocalizations.of(context)- .itemCount(- count: cachedCount,- );+ final String textCount = AppLocalizations.of(+ context,+ ).itemCount(count: cachedCount);return Column(crossAxisAlignment: CrossAxisAlignment.start,children: [@@ -363,16 +360,13 @@ class _AlbumRowSharePillContent extends StatelessWidget {final List<User> sharees;final Widget? trailingWidget;- const _AlbumRowSharePillContent({- required this.sharees,- this.trailingWidget,- });+ const _AlbumRowSharePillContent({required this.sharees, this.trailingWidget});@overrideWidget build(BuildContext context) {final displayCount = min(sharees.length, _limitCountTo);final hasMore = sharees.length > _limitCountTo;- const type = AvatarType.small;+ const type = AvatarType.xs;final double avatarSize = getAvatarSize(type);final double overlapPadding = getOverlapPadding(type);final trailingWidgetWidth = trailingWidget == null ? 0.0 : avatarSize;@@ -413,9 +407,7 @@ class _AlbumRowSharePillContent extends StatelessWidget {left: visibleAvatarsWidth,child: SizedBox.square(dimension: avatarSize,- child: Center(- child: trailingWidget!,- ),+ child: Center(child: trailingWidget!),),),);@@ -424,10 +416,7 @@ class _AlbumRowSharePillContent extends StatelessWidget {return SizedBox(width: contentWidth,height: avatarSize,- child: Stack(- clipBehavior: Clip.none,- children: widgets,- ),+ child: Stack(clipBehavior: Clip.none, children: widgets),);}}diff --git a/mobile/apps/photos/lib/ui/sharing/album_share_info_widget.dart b/mobile/apps/photos/lib/ui/sharing/album_share_info_widget.dartindex 2cb9e65175..711b9bf539 100644--- a/mobile/apps/photos/lib/ui/sharing/album_share_info_widget.dart+++ b/mobile/apps/photos/lib/ui/sharing/album_share_info_widget.dart@@ -17,7 +17,7 @@ class AlbumSharesIcons extends StatelessWidget {const AlbumSharesIcons({super.key,required this.sharees,- this.type = AvatarType.small,+ this.type = AvatarType.xs,this.limitCountTo = 2,this.removeBorder = true,this.trailingWidget,@@ -57,7 +57,8 @@ class AlbumSharesIcons extends StatelessWidget {if (trailingWidget != null) {widgets.add(Positioned(- left: (overlapPadding * (displayCount + (hasMore ? 1 : 0))) ++ left:+ (overlapPadding * (displayCount + (hasMore ? 1 : 0))) +(displayCount > 0 ? 12 : 0),child: trailingWidget!,),@@ -77,8 +78,10 @@ class AlbumSharesIcons extends StatelessWidget {double getOverlapPadding(AvatarType type) {switch (type) {- case AvatarType.small:+ case AvatarType.xs:return 12.0;+ case AvatarType.small:+ return 14.0;case AvatarType.medium:return 18.0;case AvatarType.regular:@@ -92,6 +95,8 @@ double getOverlapPadding(AvatarType type) {MoreCountType moreCountTypeFromAvatarType(AvatarType type) {switch (type) {+ case AvatarType.xs:+ return MoreCountType.xs;case AvatarType.small:return MoreCountType.small;case AvatarType.medium:diff --git a/mobile/apps/photos/lib/ui/sharing/more_count_badge.dart b/mobile/apps/photos/lib/ui/sharing/more_count_badge.dartindex 6d4f07ef31..3abdbffd5a 100644--- a/mobile/apps/photos/lib/ui/sharing/more_count_badge.dart+++ b/mobile/apps/photos/lib/ui/sharing/more_count_badge.dart@@ -3,7 +3,7 @@ import 'package:photos/theme/colors.dart';import 'package:photos/theme/ente_theme.dart';import 'package:tuple/tuple.dart';-enum MoreCountType { small, medium, regular, large, huge }+enum MoreCountType { xs, small, medium, regular, large, huge }class MoreCountWidget extends StatelessWidget {final MoreCountType type;@@ -75,6 +75,8 @@ class MoreCountWidget extends StatelessWidget {case MoreCountType.medium:return Tuple2(24.0, enteTextTheme.mini);case MoreCountType.small:+ return Tuple2(20.0, enteTextTheme.tiny);+ case MoreCountType.xs:return Tuple2(16.0, enteTextTheme.tiny);}}diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dartindex fe8e0bfb46..c969a8b15b 100644--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart@@ -15,7 +15,7 @@ import 'package:photos/theme/ente_theme.dart';import "package:photos/ui/viewer/people/person_face_widget.dart";import 'package:tuple/tuple.dart';-enum AvatarType { small, medium, regular, large, huge }+enum AvatarType { xs, small, medium, regular, large, huge }class UserAvatarWidget extends StatefulWidget {final User user;@@ -56,19 +56,21 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {void initState() {super.initState();_reload();- _peopleChangedSubscription =- Bus.instance.on<PeopleChangedEvent>().listen((event) {+ _peopleChangedSubscription = Bus.instance.on<PeopleChangedEvent>().listen((+ event,+ ) {if (event.type == PeopleEventType.saveOrEditPerson ||event.type == PeopleEventType.syncDone) {_reload();}});- _contactsChangedSubscription =- Bus.instance.on<ContactsChangedEvent>().listen((event) {- if (event.matchesContactUserId(widget.user.id)) {- _reload();- }- });+ _contactsChangedSubscription = Bus.instance+ .on<ContactsChangedEvent>()+ .listen((event) {+ if (event.matchesContactUserId(widget.user.id)) {+ _reload();+ }+ });}@override@@ -93,7 +95,8 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {if (!mounted) return;setState(() {final data = PersonService- .instance.emailToPartialPersonDataMapCache[widget.user.email];+ .instance+ .emailToPartialPersonDataMapCache[widget.user.email];if (data != null && data.containsKey(PersonService.kPersonIDKey)) {_canUsePersonFaceWidget = true;_personId = data[PersonService.kPersonIDKey] as String;@@ -113,10 +116,8 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {return;}final loadGeneration = ++_photoLoadGeneration;- final photoBytes =- await PhotosContactsService.instance.getProfilePictureBytesByUserId(- userId,- );+ final photoBytes = await PhotosContactsService.instance+ .getProfilePictureBytesByUserId(userId);if (!mounted ||loadGeneration != _photoLoadGeneration ||widget.user.id != userId) {@@ -131,8 +132,8 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {@overrideWidget build(BuildContext context) {final double size = getAvatarSize(widget.type);- final int cachedPixelWidth =- (size * MediaQuery.devicePixelRatioOf(context)).toInt();+ final int cachedPixelWidth = (size * MediaQuery.devicePixelRatioOf(context))+ .toInt();if (_contactPhotoBytes != null) {return SizedBox(height: size,@@ -207,8 +208,8 @@ class _FirstLetterCircularAvatarStatefinal resolvedDisplayName = resolveDisplayName(widget.user);final displayChar = resolvedDisplayName.isEmpty? ((widget.user.email.isEmpty)- ? " "- : widget.user.email.substring(0, 1))+ ? " "+ : widget.user.email.substring(0, 1)): resolvedDisplayName.substring(0, 1);Color decorationColor;if (widget.user.email == Configuration.instance.getEmail()) {@@ -253,14 +254,14 @@ class _FirstLetterCircularAvatarStatecase AvatarType.medium:return Tuple2(24.0, enteTextTheme.mini);case AvatarType.small:+ return Tuple2(20.0, enteTextTheme.tiny);+ case AvatarType.xs:return Tuple2(16.0, enteTextTheme.tiny);}}}-double getAvatarSize(- AvatarType type,-) {+double getAvatarSize(AvatarType type) {switch (type) {case AvatarType.huge:return 56.0;@@ -271,6 +272,8 @@ double getAvatarSize(case AvatarType.medium:return 24.0;case AvatarType.small:+ return 20.0;+ case AvatarType.xs:return 16.0;}}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dartindex 2d16e4419d..88f1ca7af0 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart@@ -29,10 +29,7 @@ class UnSyncedIcon extends StatelessWidget {@overrideWidget build(BuildContext context) {- return const _BottomLeftOverlayIcon(- Icons.cloud_off_outlined,- baseSize: 18,- );+ return const _BottomLeftOverlayIcon(Icons.cloud_off_outlined, baseSize: 18);}}@@ -67,10 +64,7 @@ class FavoriteOverlayIcon extends StatelessWidget {@overrideWidget build(BuildContext context) {- return const _BottomLeftOverlayIcon(- EnteIcons.favoriteFilled,- baseSize: 22,- );+ return const _BottomLeftOverlayIcon(EnteIcons.favoriteFilled, baseSize: 22);}}@@ -104,10 +98,7 @@ class LivePhotoOverlayIcon extends StatelessWidget {@overrideWidget build(BuildContext context) {- return const _BottomRightOverlayIcon(- Icons.album_outlined,- baseSize: 18,- );+ return const _BottomRightOverlayIcon(Icons.album_outlined, baseSize: 18);}}@@ -197,7 +188,12 @@ class VideoOverlayDuration extends StatelessWidget {class OwnerAvatarOverlayIcon extends StatelessWidget {final User user;- const OwnerAvatarOverlayIcon(this.user, {super.key});+ final AvatarType type;+ const OwnerAvatarOverlayIcon(+ this.user, {+ super.key,+ this.type = AvatarType.small,+ });@overrideWidget build(BuildContext context) {@@ -205,11 +201,7 @@ class OwnerAvatarOverlayIcon extends StatelessWidget {alignment: Alignment.topRight,child: Padding(padding: const EdgeInsets.only(right: 4, top: 4),- child: UserAvatarWidget(- user,- type: AvatarType.small,- thumbnailView: true,- ),+ child: UserAvatarWidget(user, type: type, thumbnailView: true),),);}@@ -326,11 +318,7 @@ class _BottomLeftOverlayIcon extends StatelessWidget {alignment: Alignment.bottomLeft,child: Padding(padding: EdgeInsets.only(left: inset, bottom: inset),- child: Icon(- icon,- size: size,- color: color,- ),+ child: Icon(icon, size: size, color: color),),),);@@ -399,18 +387,10 @@ class _BottomRightOverlayIcon extends StatelessWidget {child: Padding(padding: EdgeInsets.only(bottom: inset, right: inset),child: rotationAngle == null- ? Icon(- icon,- size: size,- color: color,- )+ ? Icon(icon, size: size, color: color): Transform.rotate(angle: rotationAngle!, // rotate by 45 degrees- child: Icon(- icon,- size: size,- color: color,- ),+ child: Icon(icon, size: size, color: color),),),),diff --git a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dartindex daac4fab55..30a446af81 100644--- a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart@@ -23,6 +23,7 @@ import 'package:photos/models/gallery_type.dart';import 'package:photos/service_locator.dart';import 'package:photos/services/collections_service.dart';import 'package:photos/services/favorites_service.dart';+import "package:photos/ui/sharing/user_avator_widget.dart";import 'package:photos/ui/viewer/file/file_icons_widget.dart';import 'package:photos/ui/viewer/gallery/component/group/type.dart';import 'package:photos/ui/viewer/gallery/state/gallery_context_state.dart';@@ -45,6 +46,7 @@ class ThumbnailWidget extends StatefulWidget {final int thumbnailSize;final bool useRequestedThumbnailSizeForLocalCache;final bool shouldShowOwnerAvatar;+ final AvatarType ownerAvatarType;final bool shouldShowFavoriteIcon;///On video thumbnails, shows the video duration if true. If false,@@ -63,6 +65,7 @@ class ThumbnailWidget extends StatefulWidget {this.shouldShowPinIcon = false,this.showFavForAlbumOnly = false,this.shouldShowOwnerAvatar = false,+ this.ownerAvatarType = AvatarType.small,this.diskLoadDeferDuration,this.serverLoadDeferDuration,this.thumbnailSize = thumbnailSmallSize,@@ -198,7 +201,8 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {if (widget.rawThumbnail) {return image;}- final shouldShowOwnerAvatar = widget.shouldShowOwnerAvatar &&+ final shouldShowOwnerAvatar =+ widget.shouldShowOwnerAvatar &&galleryContext?.galleryType != GalleryType.sharedPublicCollection;final List<Widget> contentChildren = [image];if (widget.shouldShowFavoriteIcon) {@@ -221,12 +225,15 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {widget.file.ownerID!,widget.file.collectionID,);- contentChildren.add(OwnerAvatarOverlayIcon(owner));+ contentChildren.add(+ OwnerAvatarOverlayIcon(owner, type: widget.ownerAvatarType),+ );} else if (widget.file.isCollect) {contentChildren.add(// Use -1 as userID for enforcing black avatar colorOwnerAvatarOverlayIcon(User(id: -1, email: '', name: widget.file.uploaderName),+ type: widget.ownerAvatarType,),);}@@ -331,60 +338,62 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {}Future _getThumbnailFromDisk() async {- return _loadWithRetry().then((thumbData) async {- if (thumbData == null) {- if (widget.file.isUploaded) {- _logger.info("Removing localID reference for " + widget.file.tag);- widget.file.localID = null;- if (widget.file.isTrash) {- unawaited(TrashDB.instance.update(widget.file as TrashFile));- } else {- unawaited(FilesDB.instance.update(widget.file));+ return _loadWithRetry()+ .then((thumbData) async {+ if (thumbData == null) {+ if (widget.file.isUploaded) {+ _logger.info("Removing localID reference for " + widget.file.tag);+ widget.file.localID = null;+ if (widget.file.isTrash) {+ unawaited(TrashDB.instance.update(widget.file as TrashFile));+ } else {+ unawaited(FilesDB.instance.update(widget.file));+ }+ _loadNetworkImage();+ } else {+ if (await doesLocalFileExist(widget.file) == false) {+ _logger.info("Deleting file " + widget.file.tag);+ await FilesDB.instance.deleteLocalFile(widget.file);+ Bus.instance.fire(+ LocalPhotosUpdatedEvent(+ [widget.file],+ type: EventType.deletedFromDevice,+ source: "thumbFileDeleted",+ ),+ );+ }+ }+ return;}- _loadNetworkImage();- } else {- if (await doesLocalFileExist(widget.file) == false) {- _logger.info("Deleting file " + widget.file.tag);- await FilesDB.instance.deleteLocalFile(widget.file);- Bus.instance.fire(- LocalPhotosUpdatedEvent(- [widget.file],- type: EventType.deletedFromDevice,- source: "thumbFileDeleted",- ),++ if (mounted) {+ final imageProvider = Image.memory(+ thumbData,+ cacheHeight: optimizedImageHeight,+ cacheWidth: optimizedImageWidth,+ ).image;+ _cacheAndRender(imageProvider);+ }+ ThumbnailInMemoryLruCache.put(+ widget.file,+ thumbData,+ _localCacheThumbnailSize,+ );+ })+ .catchError((e) {+ _errorLoadingLocalThumbnail = true;+ if (e is WidgetUnmountedException) {+ // Widget was unmounted - this is expected behavior+ _logger.fine(+ "Thumbnail loading cancelled: widget unmounted for localID: ${widget.file.localID}",+ );+ } else {+ _logger.warning(+ "Could not load thumbnail from disk for localID: ${widget.file.localID}",+ e,);}- }- return;- }-- if (mounted) {- final imageProvider = Image.memory(- thumbData,- cacheHeight: optimizedImageHeight,- cacheWidth: optimizedImageWidth,- ).image;- _cacheAndRender(imageProvider);- }- ThumbnailInMemoryLruCache.put(- widget.file,- thumbData,- _localCacheThumbnailSize,- );- }).catchError((e) {- _errorLoadingLocalThumbnail = true;- if (e is WidgetUnmountedException) {- // Widget was unmounted - this is expected behavior- _logger.fine(- "Thumbnail loading cancelled: widget unmounted for localID: ${widget.file.localID}",- );- } else {- _logger.warning(- "Could not load thumbnail from disk for localID: ${widget.file.localID}",- e,- );- }- });+ });}Future<Uint8List?> _loadWithRetry() async {diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dartindex e04b9767bf..1eef163aff 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart@@ -14,6 +14,7 @@ import "package:photos/models/selected_files.dart";import "package:photos/services/app_lifecycle_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/touch_cross_detector.dart";+import "package:photos/ui/sharing/user_avator_widget.dart";import "package:photos/ui/viewer/file/detail_page.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";import "package:photos/ui/viewer/gallery/component/swipe_selectable_file_widget.dart";@@ -56,8 +57,9 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {_isFileSelected =widget.selectedFiles?.isFileSelected(widget.file) ?? false;widget.selectedFiles?.addListener(_selectedFilesListener);- _fileUploadedSubscription =- Bus.instance.on<FileUploadedEvent>().listen((event) {+ _fileUploadedSubscription = Bus.instance.on<FileUploadedEvent>().listen((+ event,+ ) {if (event.file.generatedID != null &&event.file.generatedID == widget.file.generatedID &&mounted) {@@ -116,6 +118,9 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {? thumbnailLargeSize: thumbnailSmallSize,shouldShowOwnerAvatar: !_isFileSelected,+ ownerAvatarType: widget.photoGridSize < photoGridSizeMax+ ? AvatarType.small+ : AvatarType.xs,shouldShowVideoDuration: true,);return GestureDetector(@@ -138,14 +143,14 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {borderRadius: borderRadius,child: Hero(tag: heroTag,- flightShuttleBuilder: (- flightContext,- animation,- flightDirection,- fromHeroContext,- toHeroContext,- ) =>- thumbnailWidget,+ flightShuttleBuilder:+ (+ flightContext,+ animation,+ flightDirection,+ fromHeroContext,+ toHeroContext,+ ) => thumbnailWidget,transitionOnUserGestures: true,child: thumbnailWidget,),@@ -172,14 +177,14 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {borderRadius: borderRadius,child: Hero(tag: heroTag,- flightShuttleBuilder: (- flightContext,- animation,- flightDirection,- fromHeroContext,- toHeroContext,- ) =>- thumbnailWidget,+ flightShuttleBuilder:+ (+ flightContext,+ animation,+ flightDirection,+ fromHeroContext,+ toHeroContext,+ ) => thumbnailWidget,transitionOnUserGestures: true,child: thumbnailWidget,),@@ -217,7 +222,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {void _onTapNoSelectionLimit(BuildContext context, EnteFile file) async {final bool shouldToggleSelection =(widget.selectedFiles?.files.isNotEmpty ?? false) ||- (GalleryContextState.of(context)?.inSelectionMode ?? false);+ (GalleryContextState.of(context)?.inSelectionMode ?? false);if (shouldToggleSelection) {if (widget.selectedFiles == null) {return;diff --git a/mobile/apps/photos/test/ui/sharing/user_avatar_widget_test.dart b/mobile/apps/photos/test/ui/sharing/user_avatar_widget_test.dartnew file mode 100644index 0000000000..88027d5043--- /dev/null+++ b/mobile/apps/photos/test/ui/sharing/user_avatar_widget_test.dart@@ -0,0 +1,20 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:photos/ui/sharing/album_share_info_widget.dart';+import 'package:photos/ui/sharing/more_count_badge.dart';+import 'package:photos/ui/sharing/user_avator_widget.dart';++void main() {+ test('AvatarType exposes Figma-aligned xs and small sizes', () {+ expect(getAvatarSize(AvatarType.xs), 16);+ expect(getAvatarSize(AvatarType.small), 20);+ expect(getAvatarSize(AvatarType.medium), 24);+ expect(getAvatarSize(AvatarType.regular), 28);+ expect(getAvatarSize(AvatarType.large), 32);+ expect(getAvatarSize(AvatarType.huge), 56);+ });++ test('share badges keep xs separate from small', () {+ expect(moreCountTypeFromAvatarType(AvatarType.xs), MoreCountType.xs);+ expect(moreCountTypeFromAvatarType(AvatarType.small), MoreCountType.small);+ });+}diff --git a/mobile/packages/ente_components/example/lib/main.dart b/mobile/packages/ente_components/example/lib/main.dartindex 0e8b983f23..c065cd477c 100644--- a/mobile/packages/ente_components/example/lib/main.dart+++ b/mobile/packages/ente_components/example/lib/main.dart@@ -1625,8 +1625,10 @@ class _AvatarPreview extends StatelessWidget {const _AvatarPreview();static const _sizes = [- (label: 'Default', size: AvatarComponentSize.normal),+ (label: 'XS', size: AvatarComponentSize.xs),(label: 'Small', size: AvatarComponentSize.small),+ (label: 'Default', size: AvatarComponentSize.defaultSize),+ (label: 'Medium', size: AvatarComponentSize.medium),(label: 'Large', size: AvatarComponentSize.large),(label: 'Contact (huge)', size: AvatarComponentSize.contactHuge),];@@ -1637,6 +1639,7 @@ class _AvatarPreview extends StatelessWidget {(label: 'Pink', color: AvatarComponentColor.pink, initials: 'U'),(label: 'Purple', color: AvatarComponentColor.purple, initials: 'R'),(label: 'Blue', color: AvatarComponentColor.blue, initials: 'S'),+ (label: 'Cyan', color: AvatarComponentColor.cyan, initials: 'C'),];@override@@ -1670,6 +1673,8 @@ class _AvatarPreview extends StatelessWidget {const _AvatarTableRow(label: 'Add icon',children: [+ SizedBox.shrink(),+ SizedBox.shrink(),SizedBox.shrink(),SizedBox.shrink(),SizedBox.shrink(),diff --git a/mobile/packages/ente_components/lib/components/avatar_component.dart b/mobile/packages/ente_components/lib/components/avatar_component.dartindex 1b406904b3..b556e4e66f 100644--- a/mobile/packages/ente_components/lib/components/avatar_component.dart+++ b/mobile/packages/ente_components/lib/components/avatar_component.dart@@ -5,64 +5,144 @@ import 'package:ente_components/theme/theme.dart';import 'package:flutter/material.dart';enum AvatarComponentSize {- small,- normal,- large,- contactHuge,-}+ xs(+ dimension: 16,+ borderWidth: 1,+ iconSize: 12,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 8,+ height: 15 / 8,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ small(+ dimension: 20,+ borderWidth: 1,+ iconSize: 14,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 10,+ height: 15 / 10,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ defaultSize(+ dimension: 24,+ borderWidth: 1,+ iconSize: 16,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 12,+ height: 15 / 12,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ @Deprecated('Use AvatarComponentSize.defaultSize instead.')+ normal(+ dimension: 24,+ borderWidth: 1,+ iconSize: 16,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 12,+ height: 15 / 12,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ medium(+ dimension: 28,+ borderWidth: 1,+ iconSize: 18,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 12,+ height: 15 / 12,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ large(+ dimension: 32,+ borderWidth: 2,+ iconSize: 18,+ textStyle: TextStyle(+ fontFamily: TextStyles.fontFamily,+ fontSize: 12,+ height: 15 / 12,+ fontWeight: FontWeight.w500,+ letterSpacing: 0,+ ),+ ),+ contactHuge(+ dimension: 56,+ borderWidth: 2,+ iconSize: 24,+ textStyle: TextStyles.h2,+ );++ const AvatarComponentSize({+ required this.dimension,+ required this.borderWidth,+ required this.iconSize,+ required this.textStyle,+ });-enum AvatarComponentColor {- yellow,- green,- orange,- pink,- purple,- blue,+ final double dimension;+ final double borderWidth;+ final double iconSize;+ final TextStyle textStyle;}+enum AvatarComponentColor { yellow, green, orange, pink, purple, blue, cyan }+/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2482-6547&m=dev/// Section: Labels and avatars / Avatar-/// Specs: 16px, 24px, 32px, and 56px circular avatars with image, color, and add-icon variants.+/// Specs: 16px, 20px, 24px, 28px, 32px, and 56px circular avatars with image, color, and add-icon variants.class AvatarComponent extends StatelessWidget {const AvatarComponent({super.key,this.initials = '',- this.size = AvatarComponentSize.normal,+ this.size = AvatarComponentSize.defaultSize,this.color = AvatarComponentColor.yellow,this.seed,this.semanticLabel,- }) : image = null,- icon = null;+ }) : image = null,+ icon = null;const AvatarComponent.image({super.key,required this.image,- this.size = AvatarComponentSize.normal,+ this.size = AvatarComponentSize.defaultSize,this.semanticLabel,- }) : initials = '',- color = AvatarComponentColor.yellow,- seed = null,- icon = null;+ }) : initials = '',+ color = AvatarComponentColor.yellow,+ seed = null,+ icon = null;const AvatarComponent.icon({super.key,this.icon = const Icon(Icons.add_rounded),this.size = AvatarComponentSize.contactHuge,this.semanticLabel,- }) : initials = '',- image = null,- color = AvatarComponentColor.yellow,- seed = null;+ }) : initials = '',+ image = null,+ color = AvatarComponentColor.yellow,+ seed = null;const AvatarComponent.seeded({super.key,required this.initials,required this.seed,- this.size = AvatarComponentSize.normal,+ this.size = AvatarComponentSize.defaultSize,this.semanticLabel,- }) : image = null,- color = AvatarComponentColor.yellow,- icon = null;+ }) : image = null,+ color = AvatarComponentColor.yellow,+ icon = null;final String initials;final AvatarComponentSize size;@@ -93,37 +173,34 @@ class AvatarComponent extends StatelessWidget {color: colors.backgroundBase,width: borderWidth,),- image: DecorationImage(- image: image!,- fit: BoxFit.cover,- ),+ image: DecorationImage(image: image!, fit: BoxFit.cover),),): icon != null- ? CustomPaint(- foregroundPainter: _DashedCircleBorderPainter(- color: colors.strokeFaint,- strokeWidth: borderWidth,- ),- child: DecoratedBox(- decoration: BoxDecoration(- color: colors.specialWhite,- shape: BoxShape.circle,- ),- child: Center(child: child),- ),- )- : DecoratedBox(- decoration: BoxDecoration(- color: _backgroundColor(context),- shape: BoxShape.circle,- border: Border.all(- color: colors.backgroundBase,- width: borderWidth,- ),- ),- child: Center(child: child),+ ? CustomPaint(+ foregroundPainter: _DashedCircleBorderPainter(+ color: colors.strokeFaint,+ strokeWidth: borderWidth,+ ),+ child: DecoratedBox(+ decoration: BoxDecoration(+ color: colors.specialWhite,+ shape: BoxShape.circle,+ ),+ child: Center(child: child),+ ),+ )+ : DecoratedBox(+ decoration: BoxDecoration(+ color: _backgroundColor(context),+ shape: BoxShape.circle,+ border: Border.all(+ color: colors.backgroundBase,+ width: borderWidth,),+ ),+ child: Center(child: child),+ ),),);}@@ -149,8 +226,9 @@ class AvatarComponent extends StatelessWidget {text,maxLines: 1,textAlign: TextAlign.center,- style: size.textStyle- .copyWith(color: context.componentColors.specialWhite),+ style: size.textStyle.copyWith(+ color: context.componentColors.specialWhite,+ ),),);}@@ -171,6 +249,7 @@ class AvatarComponent extends StatelessWidget {AvatarComponentColor.pink => colors.accentPink,AvatarComponentColor.purple => colors.purple,AvatarComponentColor.blue => colors.blue,+ AvatarComponentColor.cyan => avatarCyan,};}@@ -182,55 +261,6 @@ class AvatarComponent extends StatelessWidget {}}-extension on AvatarComponentSize {- double get dimension {- return switch (this) {- AvatarComponentSize.small => 16,- AvatarComponentSize.normal => 24,- AvatarComponentSize.large => 32,- AvatarComponentSize.contactHuge => 56,- };- }-- double get borderWidth {- return switch (this) {- AvatarComponentSize.small || AvatarComponentSize.normal => 1,- AvatarComponentSize.large || AvatarComponentSize.contactHuge => 2,- };- }-- double get iconSize {- return switch (this) {- AvatarComponentSize.contactHuge => 24,- AvatarComponentSize.large => 18,- AvatarComponentSize.normal => 16,- AvatarComponentSize.small => 12,- };- }-- TextStyle get textStyle {- return switch (this) {- AvatarComponentSize.small => const TextStyle(- fontFamily: TextStyles.fontFamily,- fontSize: 8,- height: 15 / 8,- fontWeight: FontWeight.w500,- letterSpacing: 0,- ),- AvatarComponentSize.contactHuge => TextStyles.h2,- AvatarComponentSize.normal ||- AvatarComponentSize.large =>- const TextStyle(- fontFamily: TextStyles.fontFamily,- fontSize: 12,- height: 15 / 12,- fontWeight: FontWeight.w500,- letterSpacing: 0,- ),- };- }-}-class _DashedCircleBorderPainter extends CustomPainter {const _DashedCircleBorderPainter({required this.color,diff --git a/mobile/packages/ente_components/lib/theme/colors.dart b/mobile/packages/ente_components/lib/theme/colors.dartindex 6beafa6161..55a0933aa4 100644--- a/mobile/packages/ente_components/lib/theme/colors.dart+++ b/mobile/packages/ente_components/lib/theme/colors.dart@@ -601,6 +601,8 @@ const Color specialWhiteDark = Color.fromRGBO(255, 255, 255, 1);const Color specialWhiteOverlayLight = Color.fromRGBO(255, 255, 255, 0.14);const Color specialWhiteOverlayDark = Color.fromRGBO(255, 255, 255, 0.14);+const Color avatarCyan = Color.fromRGBO(0, 184, 212, 1);+const List<Color> avatarLight = [Color.fromRGBO(118, 84, 154, 1),Color.fromRGBO(223, 120, 97, 1),diff --git a/mobile/packages/ente_components/test/components/avatar_test.dart b/mobile/packages/ente_components/test/components/avatar_test.dartindex 5267233b22..89c6feec6b 100644--- a/mobile/packages/ente_components/test/components/avatar_test.dart+++ b/mobile/packages/ente_components/test/components/avatar_test.dart@@ -11,8 +11,10 @@ void main() {_wrap(const Column(children: [+ AvatarComponent(initials: 'E', size: AvatarComponentSize.xs),AvatarComponent(initials: 'E', size: AvatarComponentSize.small),AvatarComponent(initials: 'E'),+ AvatarComponent(initials: 'E', size: AvatarComponentSize.medium),AvatarComponent(initials: 'E', size: AvatarComponentSize.large),AvatarComponent(initials: 'E',@@ -25,47 +27,56 @@ void main() {final surfaces = find.byKey(const ValueKey('avatar-surface'));expect(tester.getSize(surfaces.at(0)), const Size(16, 16));- expect(tester.getSize(surfaces.at(1)), const Size(24, 24));- expect(tester.getSize(surfaces.at(2)), const Size(32, 32));- expect(tester.getSize(surfaces.at(3)), const Size(56, 56));+ expect(tester.getSize(surfaces.at(1)), const Size(20, 20));+ expect(tester.getSize(surfaces.at(2)), const Size(24, 24));+ expect(tester.getSize(surfaces.at(3)), const Size(28, 28));+ expect(tester.getSize(surfaces.at(4)), const Size(32, 32));+ expect(tester.getSize(surfaces.at(5)), const Size(56, 56));});testWidgets(- 'AvatarComponent supports image, icon, named colors, and seed colors', (- tester,- ) async {- await tester.pumpWidget(- _wrap(- Column(- children: [- AvatarComponent.image(image: MemoryImage(_transparentPng)),- const AvatarComponent.icon(),- const AvatarComponent(- initials: 'K',- color: AvatarComponentColor.green,- ),- const AvatarComponent.seeded(- initials: 'A',- seed: 0,- ),- ],+ 'AvatarComponent supports image, icon, named colors, and seed colors',+ (tester) async {+ await tester.pumpWidget(+ _wrap(+ Column(+ children: [+ AvatarComponent.image(image: MemoryImage(_transparentPng)),+ const AvatarComponent.icon(),+ const AvatarComponent(+ initials: 'K',+ color: AvatarComponentColor.green,+ ),+ const AvatarComponent(+ initials: 'C',+ color: AvatarComponentColor.cyan,+ ),+ const AvatarComponent.seeded(initials: 'A', seed: 0),+ ],+ ),),- ),- );+ );- expect(find.byIcon(Icons.add_rounded), findsOneWidget);- expect(find.text('K'), findsOneWidget);- expect(find.text('A'), findsOneWidget);- expect(avatarLight.length, avatarDark.length);- });+ expect(find.byIcon(Icons.add_rounded), findsOneWidget);+ expect(find.text('K'), findsOneWidget);+ expect(find.text('C'), findsOneWidget);+ expect(find.text('A'), findsOneWidget);+ expect(avatarLight.length, avatarDark.length);++ final cyanAvatar = tester.widget<DecoratedBox>(+ find+ .ancestor(of: find.text('C'), matching: find.byType(DecoratedBox))+ .first,+ );+ expect((cyanAvatar.decoration as BoxDecoration).color, avatarCyan);+ },+ );}Widget _wrap(Widget child) {return MaterialApp(theme: ComponentTheme.lightTheme(),- home: Scaffold(- body: Center(child: child),- ),+ home: Scaffold(body: Center(child: child)),);}