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