1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 14:29:22 +00:00
comunicmobile/lib/ui/screens/group_sections/forez_presence_section.dart

89 lines
2.6 KiB
Dart
Raw Normal View History

2021-04-22 13:41:35 +00:00
import 'package:comunic/helpers/forez_presence_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/forez_presences_set.dart';
import 'package:comunic/lists/users_list.dart';
2021-04-22 13:54:30 +00:00
import 'package:comunic/ui/routes/forez_presence_settings_route.dart';
2021-04-22 13:41:35 +00:00
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
2021-04-22 13:15:40 +00:00
import 'package:flutter/material.dart';
/// Forez presence section
///
/// @author Pierre Hubert
class ForezPresenceSection extends StatefulWidget {
2021-04-22 13:41:35 +00:00
final int groupID;
const ForezPresenceSection({
Key? key,
required this.groupID,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2021-04-22 13:41:35 +00:00
2021-04-22 13:15:40 +00:00
@override
_ForezPresenceSectionState createState() => _ForezPresenceSectionState();
}
class _ForezPresenceSectionState extends State<ForezPresenceSection> {
PresenceSet? _presences;
late UsersList _users;
2021-04-22 13:41:35 +00:00
DateTime _currentDay = DateTime.now();
List<int> get _currentListOfUsers => _presences!.getUsersAtDate(_currentDay);
2021-04-22 13:41:35 +00:00
Future<void> _refresh() async {
await ForezPresenceHelper.refreshCache(widget.groupID);
_presences = await ForezPresenceHelper.getAll(widget.groupID);
_users = await UsersHelper().getList(_presences!.usersID);
2021-04-22 13:41:35 +00:00
}
2021-04-22 13:15:40 +00:00
@override
Widget build(BuildContext context) {
2021-04-22 13:41:35 +00:00
return Stack(
children: <Widget>[
AsyncScreenWidget(
onReload: _refresh,
onBuild: _buildList,
errorMessage: "Erreur lors du chargement des présences !",
),
Positioned(
right: 10,
bottom: 10,
child: FloatingActionButton(
backgroundColor: Colors.green,
2021-04-22 13:54:30 +00:00
onPressed: () => showPresenceSettingsRoute(context, widget.groupID),
2021-04-22 13:41:35 +00:00
child: Icon(Icons.edit),
),
)
],
);
}
Widget _buildList() {
final currentList = _currentListOfUsers;
return ListView.builder(
itemCount: currentList.length + 1,
itemBuilder: (c, i) =>
i == 0 ? _buildCalendar() : _buildUser(currentList[i - 1]),
);
}
Widget _buildCalendar() => PresenceCalendarWidget(
presenceSet: _presences!,
2021-04-22 13:41:35 +00:00
mode: CalendarDisplayMode.MULTIPLE_USERS,
selectedDay: _currentDay,
onDayClicked: _selectDay,
);
void _selectDay(DateTime dt) => setState(() => _currentDay = dt);
Widget _buildUser(int userID) {
final user = _users.getUser(userID);
return ListTile(
leading: AccountImageWidget(user: user),
title: Text(user.fullName),
);
2021-04-22 13:15:40 +00:00
}
}