1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-29 06:18:51 +00:00
comunicmobile/lib/ui/widgets/tablet_mode/tablet_appbar_widget.dart

85 lines
2.7 KiB
Dart
Raw Normal View History

import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/notifications_helper.dart';
import 'package:comunic/models/count_unread_notifications.dart';
import 'package:comunic/ui/screens/notifications_screen.dart';
import 'package:comunic/ui/screens/unread_conversations_screen.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
2020-05-07 11:49:40 +00:00
import 'package:comunic/ui/widgets/tablet_mode/appbar_custom_dropdown_widget.dart';
import 'package:flutter/material.dart';
2020-05-06 16:54:32 +00:00
/// Comunic tablet AppBar widget
///
/// @author Pierre Hubert
2020-05-06 16:54:32 +00:00
class ComunicTabletAppBarWidget extends StatefulWidget
implements PreferredSizeWidget {
@override
2020-05-06 16:54:32 +00:00
_ComunicTabletAppBarWidgetState createState() =>
_ComunicTabletAppBarWidgetState();
@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
2020-05-06 16:54:32 +00:00
class _ComunicTabletAppBarWidgetState
extends SafeState<ComunicTabletAppBarWidget> {
final notificationsDropdownKey = GlobalKey<AppBarCustomDropDownWidgetState>();
final conversationsDropdownKey = GlobalKey<AppBarCustomDropDownWidgetState>();
var _unreadNotifications =
CountUnreadNotifications(notifications: 0, conversations: 0);
void _refreshCountUnread() async {
try {
final count = await NotificationsHelper().countUnread();
setState(() {
_unreadNotifications = count;
});
} catch (e, s) {
print("Could not refresh the number of unread notifications: $e\n$s");
}
}
@override
void initState() {
super.initState();
_refreshCountUnread();
// Listen to notifications number update
this.listenChangeState<NewNumberNotifsEvent>(
(d) => _unreadNotifications.notifications = d.newNum);
this.listenChangeState<NewNumberUnreadConversations>(
(d) => _unreadNotifications.conversations = d.newNum);
}
@override
Widget build(BuildContext context) {
return AppBar(
title: Text("Comunic"),
actions: <Widget>[
2020-05-07 11:49:40 +00:00
AppBarCustomDropDownWidget(
key: notificationsDropdownKey,
icon: Icon(Icons.notifications),
2020-05-07 11:49:40 +00:00
notificationsBadge: _unreadNotifications.notifications,
onBuildOverlay: (c) => Padding(
padding: const EdgeInsets.all(8.0),
2020-05-07 17:13:22 +00:00
child: NotificationsScreen(useSmallDeleteButton: true),
),
),
2020-05-07 11:49:40 +00:00
AppBarCustomDropDownWidget(
key: conversationsDropdownKey,
icon: Icon(Icons.message),
2020-05-07 11:49:40 +00:00
notificationsBadge: _unreadNotifications.conversations,
2020-05-08 19:05:56 +00:00
onBuildOverlay: (c) => Padding(
padding: const EdgeInsets.all(8.0),
child: UnreadConversationsScreen(),
),
),
PopupMenuButton(itemBuilder: (c) => []),
],
);
}
}