Skip to content

Commit

Permalink
Change margin
Browse files Browse the repository at this point in the history
  • Loading branch information
Osman authored and Osman committed Mar 14, 2024
1 parent 0d23f7c commit 62cc582
Showing 1 changed file with 30 additions and 11 deletions.
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

0 comments on commit 62cc582

Please sign in to comment.