1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/ui/screens/other_friends_lists_screen.dart

108 lines
2.6 KiB
Dart
Raw Normal View History

2019-06-15 06:16:47 +00:00
import 'package:comunic/helpers/friends_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/ui/tiles/simple_user_tile.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/navigation_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Other friends list route (not intended to display current user friends list)
///
/// @author Pierre HUBERT
2020-04-16 11:13:31 +00:00
class OtherUserFriendsListScreen extends StatefulWidget {
final int userID;
2019-06-15 06:16:47 +00:00
2020-04-16 11:13:31 +00:00
const OtherUserFriendsListScreen({
2019-06-15 06:16:47 +00:00
Key key,
2020-04-16 11:13:31 +00:00
@required this.userID,
}) : assert(userID != null),
2019-06-15 06:16:47 +00:00
super(key: key);
@override
2020-04-16 11:13:31 +00:00
_OtherUserFriendsListScreenState createState() =>
_OtherUserFriendsListScreenState();
2019-06-15 06:16:47 +00:00
}
2020-04-16 11:13:31 +00:00
class _OtherUserFriendsListScreenState
extends State<OtherUserFriendsListScreen> {
2019-06-15 06:16:47 +00:00
final FriendsHelper friendsHelper = FriendsHelper();
final UsersHelper usersHelper = UsersHelper();
UsersList _list;
bool _error = false;
2020-04-16 11:13:31 +00:00
String get _routeName => tr("Friends of %name%",
args: {"name": _list.getUser(widget.userID).displayName});
2019-06-15 06:16:47 +00:00
void setError(bool e) => setState(() => _error = e);
@override
void didChangeDependencies() {
super.didChangeDependencies();
load();
}
/// Load the list of friends of the user
Future<void> load() async {
setError(false);
try {
2020-04-16 11:13:31 +00:00
final list = await usersHelper
.getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
..add(widget.userID));
2019-06-15 06:16:47 +00:00
setState(() {
_list = list;
});
} catch (e, st) {
print(e);
print(st);
setError(true);
}
}
@override
Widget build(BuildContext context) {
if (_error) return _buildError();
2020-04-16 11:13:31 +00:00
if (_list == null) return buildCenteredProgressBar();
2019-06-15 06:16:47 +00:00
return Scaffold(
appBar: AppBar(
title: Text(_routeName),
),
body: ListView.builder(
itemCount: _list.length,
itemBuilder: (c, i) => SimpleUserTile(
2020-04-16 11:13:31 +00:00
user: _list[i],
onTap: (u) => openUserPage(
context: context,
userID: u.id,
),
),
2019-06-15 06:16:47 +00:00
),
);
}
Widget _buildError() {
return Scaffold(
body: buildErrorCard(
tr(
2020-04-16 11:13:31 +00:00
"Could not get the list of friends of this user !",
2019-06-15 06:16:47 +00:00
),
actions: [
FlatButton(
child: Text(
tr("Try again").toUpperCase(),
style: TextStyle(color: Colors.white),
),
onPressed: load,
)
],
),
);
}
}