mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-04-26 20:37:51 +02:00
perf: Use valuenotifier to not rebuild chatlist
This commit is contained in:
parent
623c3bfc2e
commit
b0a58d8524
@ -253,7 +253,7 @@ class ChatListController extends State<ChatList>
|
|||||||
BoxConstraints? snappingSheetContainerSize;
|
BoxConstraints? snappingSheetContainerSize;
|
||||||
|
|
||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
bool scrolledToTop = true;
|
final ValueNotifier<bool> scrolledToTop = ValueNotifier(true);
|
||||||
|
|
||||||
final StreamController<Client> _clientStream = StreamController.broadcast();
|
final StreamController<Client> _clientStream = StreamController.broadcast();
|
||||||
|
|
||||||
@ -263,10 +263,8 @@ class ChatListController extends State<ChatList>
|
|||||||
|
|
||||||
void _onScroll() {
|
void _onScroll() {
|
||||||
final newScrolledToTop = scrollController.position.pixels <= 0;
|
final newScrolledToTop = scrollController.position.pixels <= 0;
|
||||||
if (newScrolledToTop != scrolledToTop) {
|
if (newScrolledToTop != scrolledToTop.value) {
|
||||||
setState(() {
|
scrolledToTop.value = newScrolledToTop;
|
||||||
scrolledToTop = newScrolledToTop;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import 'chat_list.dart';
|
|||||||
|
|
||||||
class StartChatFloatingActionButton extends StatelessWidget {
|
class StartChatFloatingActionButton extends StatelessWidget {
|
||||||
final ActiveFilter activeFilter;
|
final ActiveFilter activeFilter;
|
||||||
final bool scrolledToTop;
|
final ValueNotifier<bool> scrolledToTop;
|
||||||
final bool roomsIsEmpty;
|
final bool roomsIsEmpty;
|
||||||
|
|
||||||
const StartChatFloatingActionButton({
|
const StartChatFloatingActionButton({
|
||||||
@ -61,27 +61,30 @@ class StartChatFloatingActionButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedContainer(
|
return ValueListenableBuilder<bool>(
|
||||||
duration: FluffyThemes.animationDuration,
|
valueListenable: scrolledToTop,
|
||||||
curve: FluffyThemes.animationCurve,
|
builder: (context, scrolledToTop, _) => AnimatedContainer(
|
||||||
width: roomsIsEmpty
|
duration: FluffyThemes.animationDuration,
|
||||||
? null
|
curve: FluffyThemes.animationCurve,
|
||||||
: scrolledToTop
|
width: roomsIsEmpty
|
||||||
? 144
|
? null
|
||||||
: 56,
|
: scrolledToTop
|
||||||
child: scrolledToTop
|
? 144
|
||||||
? FloatingActionButton.extended(
|
: 56,
|
||||||
onPressed: () => _onPressed(context),
|
child: scrolledToTop
|
||||||
icon: Icon(icon),
|
? FloatingActionButton.extended(
|
||||||
label: Text(
|
onPressed: () => _onPressed(context),
|
||||||
getLabel(context),
|
icon: Icon(icon),
|
||||||
overflow: TextOverflow.fade,
|
label: Text(
|
||||||
|
getLabel(context),
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: FloatingActionButton(
|
||||||
|
onPressed: () => _onPressed(context),
|
||||||
|
child: Icon(icon),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
: FloatingActionButton(
|
|
||||||
onPressed: () => _onPressed(context),
|
|
||||||
child: Icon(icon),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user