mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-26 11:20:44 +01:00
fix: Update contact list
This commit is contained in:
parent
fe13778eb6
commit
d870ec3029
@ -23,6 +23,7 @@ class _ContactListState extends State<ContactList> {
|
|||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
StreamSubscription _onAppBarButtonTapSub;
|
StreamSubscription _onAppBarButtonTapSub;
|
||||||
|
StreamSubscription _onSync;
|
||||||
final GlobalKey<DefaultAppBarSearchFieldState> _searchField = GlobalKey();
|
final GlobalKey<DefaultAppBarSearchFieldState> _searchField = GlobalKey();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -43,12 +44,31 @@ class _ContactListState extends State<ContactList> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_onSync?.cancel();
|
||||||
_onAppBarButtonTapSub?.cancel();
|
_onAppBarButtonTapSub?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DateTime _lastSetState = DateTime.now();
|
||||||
|
Timer _coolDown;
|
||||||
|
|
||||||
|
void _updateView() {
|
||||||
|
_lastSetState = DateTime.now();
|
||||||
|
setState(() => null);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return ListView(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
children: [
|
children: [
|
||||||
@ -74,64 +94,60 @@ class _ContactListState extends State<ContactList> {
|
|||||||
AdaptivePageLayout.of(context).pushNamed('/newprivatechat'),
|
AdaptivePageLayout.of(context).pushNamed('/newprivatechat'),
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
StreamBuilder<Object>(
|
Builder(builder: (context) {
|
||||||
stream: Matrix.of(context).client.onSync.stream,
|
final contactList = Matrix.of(context)
|
||||||
builder: (context, snapshot) {
|
.client
|
||||||
final contactList = Matrix.of(context)
|
.contactList
|
||||||
.client
|
.where((p) =>
|
||||||
.contactList
|
p.senderId.toLowerCase().contains(_searchQuery.toLowerCase()))
|
||||||
.where((p) => p.senderId
|
.toList();
|
||||||
.toLowerCase()
|
if (contactList.isEmpty) {
|
||||||
.contains(_searchQuery.toLowerCase()))
|
return Column(
|
||||||
.toList();
|
children: [
|
||||||
if (contactList.isEmpty) {
|
SizedBox(height: 32),
|
||||||
return Column(
|
Icon(
|
||||||
children: [
|
Icons.people_outlined,
|
||||||
SizedBox(height: 32),
|
size: 80,
|
||||||
Icon(
|
color: Colors.grey,
|
||||||
Icons.people_outlined,
|
),
|
||||||
size: 80,
|
RaisedButton(
|
||||||
color: Colors.grey,
|
elevation: 7,
|
||||||
),
|
color: Theme.of(context).primaryColor,
|
||||||
RaisedButton(
|
shape: RoundedRectangleBorder(
|
||||||
elevation: 7,
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
color: Theme.of(context).primaryColor,
|
),
|
||||||
shape: RoundedRectangleBorder(
|
child: Row(
|
||||||
borderRadius:
|
mainAxisSize: MainAxisSize.min,
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
children: [
|
||||||
|
Icon(Icons.share_outlined, color: Colors.white),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
L10n.of(context).inviteContact,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
],
|
||||||
mainAxisSize: MainAxisSize.min,
|
),
|
||||||
children: [
|
onPressed: () => FluffyShare.share(
|
||||||
Icon(Icons.share_outlined, color: Colors.white),
|
L10n.of(context).inviteText(
|
||||||
SizedBox(width: 16),
|
Matrix.of(context).client.userID,
|
||||||
Text(
|
'https://matrix.to/#/${Matrix.of(context).client.userID}'),
|
||||||
L10n.of(context).inviteContact,
|
context),
|
||||||
style: TextStyle(
|
),
|
||||||
color: Colors.white,
|
],
|
||||||
fontSize: 16,
|
);
|
||||||
),
|
}
|
||||||
),
|
return ListView.builder(
|
||||||
],
|
physics: NeverScrollableScrollPhysics(),
|
||||||
),
|
shrinkWrap: true,
|
||||||
onPressed: () => FluffyShare.share(
|
padding: EdgeInsets.only(bottom: 24),
|
||||||
L10n.of(context).inviteText(
|
itemCount: contactList.length,
|
||||||
Matrix.of(context).client.userID,
|
itemBuilder: (context, i) =>
|
||||||
'https://matrix.to/#/${Matrix.of(context).client.userID}'),
|
ContactListTile(contact: contactList[i]),
|
||||||
context),
|
);
|
||||||
),
|
}),
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return ListView.builder(
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
padding: EdgeInsets.only(bottom: 24),
|
|
||||||
itemCount: contactList.length,
|
|
||||||
itemBuilder: (context, i) =>
|
|
||||||
ContactListTile(contact: contactList[i]),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user