1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/widgets/tablet_mode/tablet_navbar_widget.dart

72 lines
2.0 KiB
Dart

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/widgets/icon_button_badge.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:flutter/material.dart';
/// Comunic tablet navbar widget
///
/// @author Pierre Hubert
class ComunicTabletNavbarWidget extends StatefulWidget
implements PreferredSizeWidget {
@override
_ComunicTabletNavbarWidgetState createState() =>
_ComunicTabletNavbarWidgetState();
@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
class _ComunicTabletNavbarWidgetState
extends SafeState<ComunicTabletNavbarWidget> {
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>[
IconButtonWithBadge(
icon: Icon(Icons.notifications),
onPressed: () {},
number: _unreadNotifications.notifications,
),
IconButtonWithBadge(
icon: Icon(Icons.message),
onPressed: () {},
number: _unreadNotifications.conversations,
),
PopupMenuButton(itemBuilder: (c) => []),
],
);
}
}