Skip to content

Commit

Permalink
Ensure the avatar is refreshed when the widget data changed after init
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn committed Mar 6, 2024
1 parent 4df152c commit 98a2552
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/src/acter_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,26 @@ class _ActerAvatar extends State<ActerAvatar> {
@override
void initState() {
super.initState();
_refreshAvatar();
}

@override
void didUpdateWidget(ActerAvatar oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.avatarInfo.avatar != oldWidget.avatarInfo.avatar ||
widget.avatarInfo.avatarFuture != oldWidget.avatarInfo.avatarFuture) {
_refreshAvatar();
}
}

void _refreshAvatar() {
ImageStreamListener listener =
ImageStreamListener(setImage, onError: setImageError);

// reset
avatar = null;
imgSuccess = false;

if (widget.avatarInfo.avatar != null) {
widget.avatarInfo.avatar!
.resolve(ImageConfiguration())
Expand Down

0 comments on commit 98a2552

Please sign in to comment.