Browse Source

Merge pull request #368 from provokateurin/fix/user-avatars

Cleanup user avatars
pull/376/head
Kate 2 years ago committed by GitHub
parent
commit
42b7f78790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      packages/neon/neon/lib/src/widgets/user_avatar.dart

9
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -11,6 +11,8 @@ class NeonUserAvatar extends StatefulWidget {
final String? username, final String? username,
this.showStatus = true, this.showStatus = true,
this.size = kAvatarSize, this.size = kAvatarSize,
this.backgroundColor,
this.foregroundColor,
super.key, super.key,
}) : username = username ?? account.client.username!; }) : username = username ?? account.client.username!;
@ -18,6 +20,8 @@ class NeonUserAvatar extends StatefulWidget {
final String username; final String username;
final bool showStatus; final bool showStatus;
final double size; final double size;
final Color? backgroundColor;
final Color? foregroundColor;
@override @override
State<NeonUserAvatar> createState() => _UserAvatarState(); State<NeonUserAvatar> createState() => _UserAvatarState();
@ -31,8 +35,10 @@ class _UserAvatarState extends State<NeonUserAvatar> {
void initState() { void initState() {
super.initState(); super.initState();
if (widget.showStatus) {
unawaited(_userStatusBloc.load(widget.username)); unawaited(_userStatusBloc.load(widget.username));
} }
}
@override @override
Widget build(final BuildContext context) => LayoutBuilder( Widget build(final BuildContext context) => LayoutBuilder(
@ -45,6 +51,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
children: [ children: [
CircleAvatar( CircleAvatar(
radius: size / 2, radius: size / 2,
backgroundColor: widget.backgroundColor,
child: ClipOval( child: ClipOval(
child: NeonCachedApiImage( child: NeonCachedApiImage(
account: widget.account, account: widget.account,
@ -85,7 +92,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
if (result.loading) { if (result.loading) {
child = CircularProgressIndicator( child = CircularProgressIndicator(
strokeWidth: 1.5, strokeWidth: 1.5,
color: Theme.of(context).colorScheme.onPrimary, color: widget.foregroundColor ?? Theme.of(context).colorScheme.onPrimary,
); );
} else if (result.error != null) { } else if (result.error != null) {
child = Icon( child = Icon(

Loading…
Cancel
Save