mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-28 05:48:51 +00:00
108 lines
2.6 KiB
Dart
108 lines
2.6 KiB
Dart
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
|
|
|
|
class OtherUserFriendsListScreen extends StatefulWidget {
|
|
final int userID;
|
|
|
|
const OtherUserFriendsListScreen({
|
|
Key key,
|
|
@required this.userID,
|
|
}) : assert(userID != null),
|
|
super(key: key);
|
|
|
|
@override
|
|
_OtherUserFriendsListScreenState createState() =>
|
|
_OtherUserFriendsListScreenState();
|
|
}
|
|
|
|
class _OtherUserFriendsListScreenState
|
|
extends State<OtherUserFriendsListScreen> {
|
|
final FriendsHelper friendsHelper = FriendsHelper();
|
|
final UsersHelper usersHelper = UsersHelper();
|
|
|
|
UsersList _list;
|
|
bool _error = false;
|
|
|
|
String get _routeName => tr("Friends of %name%",
|
|
args: {"name": _list.getUser(widget.userID).displayName});
|
|
|
|
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 {
|
|
final list = await usersHelper
|
|
.getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
|
|
..add(widget.userID));
|
|
|
|
setState(() {
|
|
_list = list;
|
|
});
|
|
} catch (e, st) {
|
|
print(e);
|
|
print(st);
|
|
setError(true);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (_error) return _buildError();
|
|
|
|
if (_list == null) return buildCenteredProgressBar();
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(_routeName),
|
|
),
|
|
body: ListView.builder(
|
|
itemCount: _list.length,
|
|
itemBuilder: (c, i) => SimpleUserTile(
|
|
user: _list[i],
|
|
onTap: (u) => openUserPage(
|
|
context: context,
|
|
userID: u.id,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildError() {
|
|
return Scaffold(
|
|
body: buildErrorCard(
|
|
tr(
|
|
"Could not get the list of friends of this user !",
|
|
),
|
|
actions: [
|
|
FlatButton(
|
|
child: Text(
|
|
tr("Try again").toUpperCase(),
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
onPressed: load,
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|