show indicator when theres new notifications
This commit is contained in:
parent
10d1771af9
commit
6efa92c289
|
@ -1,9 +1,12 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loris/pages/notifications/single_notif.dart';
|
||||
import '../../business_logic/websocket.dart' as websocket;
|
||||
|
||||
final notifStream = StreamController<int>();
|
||||
|
||||
class Notifications extends StatefulWidget {
|
||||
const Notifications({Key? key}) : super(key: key);
|
||||
|
||||
|
@ -26,6 +29,7 @@ class _NotificationsState extends State<Notifications> {
|
|||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
notifStream.sink.add(1);
|
||||
notifs.insert(0, notif);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ class SingleNotif extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print(content);
|
||||
return Text(content["id"].toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,19 @@ class MainScaffold extends StatefulWidget {
|
|||
|
||||
class _MainScaffoldState extends State<MainScaffold> {
|
||||
int index = 0;
|
||||
int unreadNotifs = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
notifStream.stream.listen((event) {
|
||||
if (index != 2) {
|
||||
setState(() {
|
||||
unreadNotifs = event;
|
||||
});
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -54,8 +67,12 @@ class _MainScaffoldState extends State<MainScaffold> {
|
|||
floatingActionButton: buttons[index],
|
||||
bottomNavigationBar: BottomAppBar(
|
||||
child: NavigationBar(
|
||||
onDestinationSelected: (index) =>
|
||||
setState(() => this.index = index),
|
||||
onDestinationSelected: (index) => setState(() {
|
||||
this.index = index;
|
||||
if (index == 2) {
|
||||
unreadNotifs = 0;
|
||||
}
|
||||
}),
|
||||
selectedIndex: index,
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
|
@ -63,7 +80,9 @@ class _MainScaffoldState extends State<MainScaffold> {
|
|||
NavigationDestination(
|
||||
icon: const Icon(Icons.chat), label: "chat".i18n()),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.notifications),
|
||||
icon: Icon((unreadNotifs >= 1)
|
||||
? Icons.notifications_active
|
||||
: Icons.notifications),
|
||||
label: "notifications".i18n()),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.settings), label: "settings".i18n()),
|
||||
|
|
Loading…
Reference in New Issue