mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 14:59:22 +00:00
Add RefreshIndicator on friends screen
This commit is contained in:
parent
b06c28dc87
commit
c8b68e71aa
@ -33,28 +33,31 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
_ErrorsLevel _error = _ErrorsLevel.NONE;
|
_ErrorsLevel _error = _ErrorsLevel.NONE;
|
||||||
FriendsList _friendsList;
|
FriendsList _friendsList;
|
||||||
UsersList _usersInfo;
|
UsersList _usersInfo;
|
||||||
bool _loading = true;
|
GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
||||||
|
GlobalKey<RefreshIndicatorState>();
|
||||||
|
|
||||||
/// Useful setters
|
/// Useful setters
|
||||||
set error(_ErrorsLevel err) => setState(() => _error = err);
|
set error(_ErrorsLevel err) => setState(() => _error = err);
|
||||||
|
|
||||||
set loading(bool loading) => setState(() => _loading = loading);
|
|
||||||
|
|
||||||
void _gotError() {
|
void _gotError() {
|
||||||
loading = false;
|
|
||||||
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
|
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
_loadList();
|
_loadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Refresh the list of friends
|
||||||
|
Future<void> _refreshList() async {
|
||||||
|
await _refreshIndicatorKey.currentState.show();
|
||||||
|
}
|
||||||
|
|
||||||
/// Load the list of friends
|
/// Load the list of friends
|
||||||
Future<void> _loadList() async {
|
Future<void> _loadList() async {
|
||||||
error = _ErrorsLevel.NONE;
|
error = _ErrorsLevel.NONE;
|
||||||
loading = true;
|
|
||||||
|
|
||||||
// Get the list of friends
|
// Get the list of friends
|
||||||
final list = await _friendsHelper.downloadList();
|
final list = await _friendsHelper.downloadList();
|
||||||
@ -73,7 +76,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
_friendsList = list;
|
_friendsList = list;
|
||||||
_usersInfo = users;
|
_usersInfo = users;
|
||||||
});
|
});
|
||||||
loading = false;
|
|
||||||
error = _ErrorsLevel.NONE;
|
error = _ErrorsLevel.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +84,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
tr("Could not load your list of friends!"),
|
tr("Could not load your list of friends!"),
|
||||||
actions: [
|
actions: [
|
||||||
FlatButton(
|
FlatButton(
|
||||||
onPressed: _loadList,
|
onPressed: _refreshList,
|
||||||
child: Text(
|
child: Text(
|
||||||
tr("Retry").toUpperCase(),
|
tr("Retry").toUpperCase(),
|
||||||
style: TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
@ -96,17 +98,18 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
if (_error == _ErrorsLevel.MAJOR) return _buildError();
|
if (_error == _ErrorsLevel.MAJOR) return _buildError();
|
||||||
if (_friendsList == null) return buildCenteredProgressBar();
|
if (_friendsList == null) return buildCenteredProgressBar();
|
||||||
|
|
||||||
return Stack(
|
return Column(
|
||||||
children: <Widget>[
|
|
||||||
Column(
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Check for errors
|
// Check for errors
|
||||||
Container(
|
Container(child: _error != _ErrorsLevel.NONE ? _buildError() : null),
|
||||||
child: _error != _ErrorsLevel.NONE ? _buildError() : null),
|
|
||||||
|
|
||||||
// List of friends
|
// List of friends
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: RefreshIndicator(
|
||||||
|
key: _refreshIndicatorKey,
|
||||||
|
onRefresh: _loadList,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
itemCount: _friendsList.length,
|
itemCount: _friendsList.length,
|
||||||
itemBuilder: (c, i) => _friendsList[i].accepted
|
itemBuilder: (c, i) => _friendsList[i].accepted
|
||||||
? AcceptedFriendTile(
|
? AcceptedFriendTile(
|
||||||
@ -122,17 +125,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
onRespond: _respondRequest,
|
onRespond: _respondRequest,
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
// Check if loading
|
|
||||||
Positioned(
|
|
||||||
child: Container(
|
|
||||||
child:
|
|
||||||
_loading ? Center(child: CircularProgressIndicator()) : null),
|
|
||||||
top: 16.0,
|
|
||||||
left: 0.0,
|
|
||||||
right: 0.0,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -140,23 +132,19 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
|
|
||||||
/// Respond to friendship request
|
/// Respond to friendship request
|
||||||
Future<void> _respondRequest(Friend f, bool accept) async {
|
Future<void> _respondRequest(Friend f, bool accept) async {
|
||||||
loading = true;
|
|
||||||
|
|
||||||
if (!await _friendsHelper.respondRequest(f.id, accept))
|
if (!await _friendsHelper.respondRequest(f.id, accept))
|
||||||
showSimpleSnack(context, tr("Could not respond to friendship request!"));
|
showSimpleSnack(context, tr("Could not respond to friendship request!"));
|
||||||
|
|
||||||
// Load the list of friends again
|
// Load the list of friends again
|
||||||
_loadList();
|
_refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update following status of a friend
|
/// Update following status of a friend
|
||||||
Future<void> _setFollowingFriend(Friend friend, bool follow) async {
|
Future<void> _setFollowingFriend(Friend friend, bool follow) async {
|
||||||
loading = true;
|
|
||||||
|
|
||||||
if (!await _friendsHelper.setFollowing(friend.id, follow))
|
if (!await _friendsHelper.setFollowing(friend.id, follow))
|
||||||
showSimpleSnack(context, tr("Could not update following status!"));
|
showSimpleSnack(context, tr("Could not update following status!"));
|
||||||
|
|
||||||
_loadList();
|
_refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles deletion request of a friend
|
/// Handles deletion request of a friend
|
||||||
@ -186,19 +174,16 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
if (choice == null || !choice) return;
|
if (choice == null || !choice) return;
|
||||||
|
|
||||||
// Forward the request to the server
|
// Forward the request to the server
|
||||||
loading = true;
|
|
||||||
if (!await _friendsHelper.removeFriend(f.id))
|
if (!await _friendsHelper.removeFriend(f.id))
|
||||||
showSimpleSnack(
|
showSimpleSnack(
|
||||||
context, tr("Could not delete this person from your friends list!"));
|
context, tr("Could not delete this person from your friends list!"));
|
||||||
|
|
||||||
// Refresh list
|
// Refresh list
|
||||||
_loadList();
|
_refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a private conversation for a given [friend]
|
/// Open a private conversation for a given [friend]
|
||||||
Future<void> _openPrivateConversation(Friend friend) async {
|
Future<void> _openPrivateConversation(Friend friend) async {
|
||||||
loading = true;
|
|
||||||
await openPrivateConversation(context, friend.id);
|
await openPrivateConversation(context, friend.id);
|
||||||
loading = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user