mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-10-23 15:03:22 +00:00
85 lines
2.0 KiB
Dart
85 lines
2.0 KiB
Dart
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;
|
|
});
|
|
}
|
|
}
|
|
}
|