fix: prevent avatar flickering on expand nav rail

This commit is contained in:
ggurdin 2026-01-27 13:21:18 -05:00
parent e6fbd7bffd
commit 855ea32ca7
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
2 changed files with 59 additions and 15 deletions

View file

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/themes.dart';
@ -16,6 +17,7 @@ import 'package:fluffychat/pangea/analytics_summary/level_analytics_details_cont
import 'package:fluffychat/pangea/spaces/space_constants.dart';
import 'package:fluffychat/widgets/hover_builder.dart';
import 'package:fluffychat/widgets/navigation_rail.dart';
import '../../widgets/matrix.dart';
class SpaceNavigationColumn extends StatefulWidget {
final GoRouterState state;
@ -34,6 +36,27 @@ class SpaceNavigationColumnState extends State<SpaceNavigationColumn> {
bool _hovered = false;
bool _expanded = false;
Timer? _timer;
Profile? _profile;
@override
void initState() {
super.initState();
Matrix.of(context).client.fetchOwnProfile().then((profile) {
if (mounted) {
setState(() {
_profile = profile;
});
}
});
}
void _updateProfile(Profile profile) {
if (mounted) {
setState(() {
_profile = profile;
});
}
}
void _onHoverUpdate(bool hovered) {
if (hovered == _hovered) return;
@ -130,6 +153,8 @@ class SpaceNavigationColumnState extends State<SpaceNavigationColumn> {
_cancelTimer();
setState(() => _expanded = false);
},
profile: _profile,
onProfileUpdate: _updateProfile,
),
Container(
width: 1,

View file

@ -25,6 +25,8 @@ class SpacesNavigationRail extends StatelessWidget {
final double railWidth;
final bool expanded;
final VoidCallback collapse;
final Profile? profile;
final Function(Profile) onProfileUpdate;
// Pangea#
const SpacesNavigationRail({
@ -35,7 +37,9 @@ class SpacesNavigationRail extends StatelessWidget {
required this.path,
required this.railWidth,
required this.collapse,
required this.onProfileUpdate,
this.expanded = false,
this.profile,
// Pangea#
super.key,
});
@ -111,23 +115,38 @@ class SpacesNavigationRail extends StatelessWidget {
},
backgroundColor: Colors.transparent,
icon: FutureBuilder<Profile>(
// #Pangea
initialData: profile,
// Pangea#
future: client.fetchOwnProfile(),
builder: (context, snapshot) => Stack(
alignment: Alignment.center,
children: [
Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
client.userID!.localpart,
size:
width - (isColumnMode ? 32.0 : 24.0),
// #Pangea
// builder: (context, snapshot) => Stack(
builder: (context, snapshot) {
if (snapshot.data?.avatarUrl != null &&
snapshot.data?.avatarUrl !=
profile?.avatarUrl) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => onProfileUpdate(snapshot.data!),
);
}
return Stack(
// Pangea#
alignment: Alignment.center,
children: [
Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
client.userID!.localpart,
size: width -
(isColumnMode ? 32.0 : 24.0),
),
),
),
],
),
],
);
},
),
toolTip: L10n.of(context).home,
// #Pangea