mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Start to display user groups
This commit is contained in:
84
lib/ui/screens/groups_list_screen.dart
Normal file
84
lib/ui/screens/groups_list_screen.dart
Normal file
@ -0,0 +1,84 @@
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/ui/widgets/group_icon_widget.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Groups list screen
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class GroupsListScreen extends StatefulWidget {
|
||||
@override
|
||||
_GroupsListScreenState createState() => _GroupsListScreenState();
|
||||
}
|
||||
|
||||
class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||
/// The list of groups
|
||||
GroupsList _groups;
|
||||
|
||||
bool _error = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
this._refreshList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
// Error
|
||||
buildErrorCard(
|
||||
tr("Could not load the list of groups!"),
|
||||
hide: !_error,
|
||||
actions: [
|
||||
MaterialButton(
|
||||
child: Text(tr("Try again".toUpperCase())),
|
||||
onPressed: () => _refreshList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// List of groups
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => this._refreshList(),
|
||||
child: _groups == null
|
||||
? Container()
|
||||
: ListView(
|
||||
children: _groups.values
|
||||
.map((g) => ListTile(
|
||||
leading: GroupIcon(group: g),
|
||||
title: Text(g.displayName),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Refresh the list of groups
|
||||
Future<void> _refreshList() async {
|
||||
try {
|
||||
final list = await GroupsHelper().getListUser();
|
||||
final groups = await GroupsHelper().getListOrThrow(list, force: true);
|
||||
|
||||
setState(() {
|
||||
_groups = groups;
|
||||
_error = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
||||
setState(() {
|
||||
_error = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user