fix: Update contact list

This commit is contained in:
Christian Pauly 2021-02-07 09:55:24 +01:00
parent fe13778eb6
commit d870ec3029
1 changed files with 73 additions and 57 deletions

View File

@ -23,6 +23,7 @@ class _ContactListState extends State<ContactList> {
String _searchQuery = '';
final ScrollController _scrollController = ScrollController();
StreamSubscription _onAppBarButtonTapSub;
StreamSubscription _onSync;
final GlobalKey<DefaultAppBarSearchFieldState> _searchField = GlobalKey();
@override
@ -43,12 +44,31 @@ class _ContactListState extends State<ContactList> {
@override
void dispose() {
_onSync?.cancel();
_onAppBarButtonTapSub?.cancel();
super.dispose();
}
DateTime _lastSetState = DateTime.now();
Timer _coolDown;
void _updateView() {
_lastSetState = DateTime.now();
setState(() => null);
}
@override
Widget build(BuildContext context) {
_onSync ??= Matrix.of(context).client.onSync.stream.listen((_) {
if (DateTime.now().millisecondsSinceEpoch -
_lastSetState.millisecondsSinceEpoch <
1000) {
_coolDown?.cancel();
_coolDown = Timer(Duration(seconds: 1), _updateView);
} else {
_updateView();
}
});
return ListView(
controller: _scrollController,
children: [
@ -74,15 +94,12 @@ class _ContactListState extends State<ContactList> {
AdaptivePageLayout.of(context).pushNamed('/newprivatechat'),
),
Divider(height: 1),
StreamBuilder<Object>(
stream: Matrix.of(context).client.onSync.stream,
builder: (context, snapshot) {
Builder(builder: (context) {
final contactList = Matrix.of(context)
.client
.contactList
.where((p) => p.senderId
.toLowerCase()
.contains(_searchQuery.toLowerCase()))
.where((p) =>
p.senderId.toLowerCase().contains(_searchQuery.toLowerCase()))
.toList();
if (contactList.isEmpty) {
return Column(
@ -97,8 +114,7 @@ class _ContactListState extends State<ContactList> {
elevation: 7,
color: Theme.of(context).primaryColor,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Row(
mainAxisSize: MainAxisSize.min,