Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-976 : Fix avatar sizes #38

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions lib/src/components/avatars/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,26 @@ class ZetaAvatar extends StatelessWidget {
/// Notification Badge shown at top right corner of avatar.
final ZetaIndicator? upperBadge;

bool get _showPlaceholder => image == null && (initials == null || initials!.isEmpty);
bool get _showPlaceholder =>
image == null && (initials == null || initials!.isEmpty);

@override
Widget build(BuildContext context) {
final zetaColors = Zeta.of(context).colors;

final borderSize = size.borderSize;
final sizePixels = size.pixelSize;
final contentSizePixels = size.pixelSize - (borderColor != null ? size.borderSize * 2 : 0);
final contentSizePixels =
size.pixelSize - (borderColor != null ? size.borderSize * 2 : 0);

final innerContent = ClipRRect(
borderRadius: BorderRadius.circular(64),
clipBehavior: Clip.hardEdge,
child: image ??
(_showPlaceholder
? Container(
transform: Matrix4.translationValues(-contentSizePixels * 0.2, -contentSizePixels * 0.1, 0),
transform: Matrix4.translationValues(
-contentSizePixels * 0.2, -contentSizePixels * 0.1, 0),
child: IconTheme(
data: IconThemeData(
color: Zeta.of(context).colors.cool,
Expand All @@ -118,33 +121,49 @@ class ZetaAvatar extends StatelessWidget {
)
: Center(
child: Text(
size == ZetaAvatarSize.xs ? initials!.substring(0, 1) : initials!,
style: TextStyle(fontSize: size.fontSize, letterSpacing: -0.5),
size == ZetaAvatarSize.xs
? initials!.substring(0, 1)
: initials!,
style:
TextStyle(fontSize: size.fontSize, letterSpacing: -0.5),
),
)),
);

return Stack(
children: [
Container(
margin: EdgeInsets.all(upperBadge == null && lowerBadge == null ? 0 : 3),
margin: const EdgeInsets.all(3),
width: sizePixels,
height: sizePixels,
decoration: BoxDecoration(
border: borderColor != null ? Border.all(color: borderColor!, width: borderSize / ZetaSpacing.x0_5) : null,
border: borderColor != null
? Border.all(
color: borderColor!, width: borderSize / ZetaSpacing.x0_5)
: null,
borderRadius: ZetaRadius.full,
color: backgroundColor ?? (_showPlaceholder ? zetaColors.surfacePrimary : zetaColors.cool.shade20),
color: backgroundColor ??
(_showPlaceholder
? zetaColors.surfacePrimary
: zetaColors.cool.shade20),
),
child: borderColor != null
? Container(
width: contentSizePixels,
height: contentSizePixels,
decoration: BoxDecoration(
color: _showPlaceholder ? backgroundColor ?? zetaColors.surfaceHovered : null,
border: Border.all(color: zetaColors.surfacePrimary, width: borderSize / ZetaSpacing.x0_5),
color: _showPlaceholder
? backgroundColor ?? zetaColors.surfaceHovered
: null,
border: Border.all(
color: zetaColors.surfacePrimary,
width: borderSize / ZetaSpacing.x0_5),
borderRadius: ZetaRadius.full,
),
child: ClipRRect(borderRadius: ZetaRadius.full, clipBehavior: Clip.hardEdge, child: innerContent),
child: ClipRRect(
borderRadius: ZetaRadius.full,
clipBehavior: Clip.hardEdge,
child: innerContent),
)
: DecoratedBox(
decoration: BoxDecoration(
Expand Down
Loading