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

test: avatar #183

Merged
merged 11 commits into from
Oct 11, 2024
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation

import path_provider_foundation
import shared_preferences_foundation
import sqflite
import sqflite_darwin
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand Down
22 changes: 16 additions & 6 deletions lib/src/components/avatars/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ZetaAvatar extends ZetaStatelessWidget {
(initials != null
? Center(
child: Text(
size == ZetaAvatarSize.xs ? initials!.substring(0, 1) : initials!,
initials!,
style: initialTextStyle ??
TextStyle(
fontSize: size.fontSize(context),
Expand Down Expand Up @@ -288,11 +288,10 @@ class ZetaAvatar extends ZetaStatelessWidget {
..add(StringProperty('semanticLowerBadgeValue', semanticLowerBadgeLabel))
..add(DiagnosticsProperty<TextStyle>('initialTextStyle', initialTextStyle));
}
}

extension on ZetaAvatarSize {
double pixelSize(BuildContext context) {
switch (this) {
/// Returns pixel size for [ZetaAvatarSize]
static double pixelSize(BuildContext context, ZetaAvatarSize size) {
switch (size) {
case ZetaAvatarSize.xxxl:
return Zeta.of(context).spacing.minimum * 50; // TODO(UX-1202): ZetaSpacingBase
// return ZetaSpacingBase.x50;
Expand All @@ -316,6 +315,17 @@ extension on ZetaAvatarSize {
}
}

/// Font size for initials
static double fontSize(BuildContext context, ZetaAvatarSize size) {
thelukewalton marked this conversation as resolved.
Show resolved Hide resolved
return pixelSize(context, size) * 4 / 9;
}
}

extension on ZetaAvatarSize {
double pixelSize(BuildContext context) {
return ZetaAvatar.pixelSize(context, this);
}

double borderSize(BuildContext context) {
switch (this) {
case ZetaAvatarSize.xxxl:
Expand All @@ -335,7 +345,7 @@ extension on ZetaAvatarSize {
}

double fontSize(BuildContext context) {
return pixelSize(context) * 4 / 9;
return ZetaAvatar.fontSize(context, this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension StringExtensions on String? {
final List<String> nameParts = this!.split(RegExp(r'\W+'))..removeWhere((item) => item.isEmpty);
if (nameParts.isEmpty) return '';
return (nameParts.length > 1
? nameParts[0].substring(0, 1) + nameParts[1].substring(0, 1)
? nameParts[0].substring(0, 1) + nameParts[nameParts.length - 1].substring(0, 1)
: nameParts[0].length > 1
? nameParts[0].substring(0, 2)
: nameParts[0])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading