Count and display Talk notifications in Appbar
This commit is contained in:
parent
abad04554c
commit
b285e7b82f
62
lib/app.dart
62
lib/app.dart
@ -2,7 +2,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/data/chatList/chatListProps.dart';
|
||||
import 'package:marianum_mobile/screen/pages/timetable/timetable.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'screen/pages/files/files.dart';
|
||||
import 'screen/pages/more/overhang.dart';
|
||||
import 'screen/pages/talk/chatList.dart';
|
||||
@ -23,6 +25,14 @@ class _AppState extends State<App> {
|
||||
Timer.periodic(const Duration(seconds: 30), (Timer t) => {
|
||||
setState((){}),
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
});
|
||||
Timer.periodic(const Duration(minutes: 1), (timer) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@ -78,31 +88,37 @@ class _AppState extends State<App> {
|
||||
BottomNavigationBarItem(icon: Stack(
|
||||
children: [
|
||||
const Icon(Icons.chat),
|
||||
Visibility(
|
||||
visible: true,
|
||||
child: Positioned(
|
||||
right: 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 12,
|
||||
minHeight: 12,
|
||||
),
|
||||
child: const Text(
|
||||
"1",
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 10,
|
||||
Consumer<ChatListProps>(
|
||||
builder: (context, value, child) {
|
||||
int messages = value.getRoomsResponse.data.map((e) => e.unreadMessages).reduce((a, b) => a+b);
|
||||
return Visibility(
|
||||
visible: messages > 0,
|
||||
child: Positioned(
|
||||
right: 0,
|
||||
top: 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 13,
|
||||
minHeight: 13,
|
||||
),
|
||||
child: Text(
|
||||
"$messages",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
), label: "Talk"),
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.folder), label: "Dateien"),
|
||||
|
@ -24,10 +24,6 @@ class _ChatListState extends State<ChatList> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
Timer.periodic(const Duration(minutes: 1), (timer) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
});
|
||||
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
username = value.getString("username")!
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user