Skip to content

Commit

Permalink
Final changes?
Browse files Browse the repository at this point in the history
  • Loading branch information
Daviiddoo committed Jul 26, 2024
1 parent beebd9b commit 87ed30d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions docs/pages/docs/avatar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ An image element with a fallback for representing the user.
// With Valid image.
FAvatar(
image: const NetworkImage('https://raw.githubusercontent.com/forus-labs/forui/main/samples/assets/avatar.png'),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
// With Invalid image and placeholder.
// With Invalid image and fallback.
FAvatar(
image: const NetworkImage(''),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
// With Invalid image without placeholder.
// With Invalid image without fallback.
FAvatar(image: const NetworkImage('')),
],
);
Expand All @@ -42,7 +42,7 @@ An image element with a fallback for representing the user.
```dart
FAvatar(
image: const NetworkImage('https://raw.githubusercontent.com/forus-labs/forui/main/samples/assets/avatar.png'),
placeholder: const Text('MN'),
fallback: const Text('MN'),
);
```

Expand Down Expand Up @@ -72,22 +72,22 @@ FAvatar.raw(child: const Text('MN'));
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// With placeholder widget.
// With fallback widget.
FAvatar(
image: const AssetImage(''),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
// Without placeholder widget.
// Without fallback widget.
FAvatar(image: const AssetImage('')),
],
);
```
</Tabs.Tab>
</Tabs>

### With Child widget without fallback
### Without fallback
<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='avatar' variant='raw' query={{}}/>
Expand Down
24 changes: 12 additions & 12 deletions forui/lib/src/widgets/avatar/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ part 'avatar_content.dart';
///
/// use image property to provide a profile image displayed within the circle.
/// Typically used with a user's profile image. If the image fails to load,
/// the placeholderBuilder property is used instead, which usually displays the user's initials.
/// the fallback widget is used instead, which usually displays the user's initials.
///
/// If the user's profile has no image, use the placeholderBuilder property to provide
/// If the user's profile has no image, use the fallback property to provide
/// the initials using a [Text] widget styled with [FAvatarStyle.backgroundColor].
class FAvatar extends StatelessWidget {
/// The style. Defaults to [FThemeData.avatarStyle].
Expand All @@ -27,21 +27,21 @@ class FAvatar extends StatelessWidget {
/// Typically used to display the user's initials using a [Text] widget
/// styled with [FAvatarStyle.backgroundColor].
///
/// Use image parameter to display an image; use [placeholder] for initials.
final Widget placeholder;
/// Use image parameter to display an image; use [fallback] for initials.
final Widget fallback;

/// Creates an [FAvatar].
FAvatar({
required ImageProvider image,
this.style,
this.size = 40.0,
Widget? placeholder,
Widget? fallback,
super.key,
}) : placeholder = _AvatarContent(
}) : fallback = _AvatarContent(
image: image,
style: style,
size: size,
placeholder: placeholder,
fallback: fallback,
);

/// Creates a [FAvatar] with custom child.
Expand All @@ -50,7 +50,7 @@ class FAvatar extends StatelessWidget {
this.style,
this.size = 40.0,
super.key,
}) : placeholder = child ?? _IconPlaceholder(style: style, size: size);
}) : fallback = child ?? _Placeholder(style: style, size: size);

@override
Widget build(BuildContext context) {
Expand All @@ -67,7 +67,7 @@ class FAvatar extends StatelessWidget {
clipBehavior: Clip.hardEdge,
child: DefaultTextStyle(
style: style.text,
child: placeholder,
child: fallback,
),
);
}
Expand All @@ -83,16 +83,16 @@ class FAvatar extends StatelessWidget {

/// [FAvatar]'s style.
final class FAvatarStyle with Diagnosticable {
/// The placeholder's background color.
/// The fallback's background color.
final Color backgroundColor;

/// The placeholder's color.
/// The fallback's color.
final Color foregroundColor;

/// Duration for the transition animation.
final Duration fadeInDuration;

/// The text style for the placeholder text.
/// The text style for the fallback text.
final TextStyle text;

/// Creates a [FAvatarStyle].
Expand Down
24 changes: 12 additions & 12 deletions forui/lib/src/widgets/avatar/avatar_content.dart
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
part of 'avatar.dart';

class _AvatarContent extends StatelessWidget {
final FAvatarStyle? style;
final ImageProvider image;
final double size;
final Widget? placeholder;
final FAvatarStyle? style;
final Widget? fallback;

const _AvatarContent({
required this.image,
required this.style,
required this.size,
this.placeholder,
this.style,
this.fallback,
});

@override
Widget build(BuildContext context) {
final style = this.style ?? context.theme.avatarStyle;

final placeholder = this.placeholder ?? _IconPlaceholder(style: style, size: size);
final fallback = this.fallback ?? _Placeholder(style: style, size: size);

return Image(
height: size,
width: size,
filterQuality: FilterQuality.medium,
image: image,
errorBuilder: (context, exception, stacktrace) => placeholder,
errorBuilder: (context, exception, stacktrace) => fallback,
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded) {
return child;
}
return AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
child: frame == null ? placeholder : child,
child: frame == null ? fallback : child,
);
},
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
}
return placeholder;
return fallback;
},
fit: BoxFit.cover,
);
Expand All @@ -48,17 +48,17 @@ class _AvatarContent extends StatelessWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('image', image))
..add(DoubleProperty('size', size))
..add(DiagnosticsProperty('image', image));
..add(DiagnosticsProperty('style', style));
}
}

class _IconPlaceholder extends StatelessWidget {
class _Placeholder extends StatelessWidget {
final double size;
final FAvatarStyle? style;

const _IconPlaceholder({required this.size, this.style});
const _Placeholder({required this.size, this.style});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion forui/test/src/widgets/avatar_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
data: theme,
child: FAvatar(
image: FileImage(File('./test/resources/pante.jpg')),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
),
);
Expand Down
6 changes: 3 additions & 3 deletions samples/lib/widgets/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class AvatarPage extends SampleScaffold {
children: [
FAvatar(
image: AssetImage(path('avatar.png')),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
FAvatar(
image: const AssetImage(''),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
FAvatar(
Expand Down Expand Up @@ -70,7 +70,7 @@ class AvatarInvalidPage extends SampleScaffold {
children: [
FAvatar(
image: const AssetImage(''),
placeholder: const Text('MN'),
fallback: const Text('MN'),
),
const SizedBox(width: 10),
FAvatar(
Expand Down

0 comments on commit 87ed30d

Please sign in to comment.