diff --git a/lib/app.dart b/lib/app.dart index 9c6a021..3185cb5 100644 --- a/lib/app.dart +++ b/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 { Timer.periodic(const Duration(seconds: 30), (Timer t) => { setState((){}), }); + + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + Provider.of(context, listen: false).run(); + }); + Timer.periodic(const Duration(minutes: 1), (timer) { + Provider.of(context, listen: false).run(); + }); + super.initState(); } @@ -78,31 +88,37 @@ class _AppState extends State { 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( + 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"), diff --git a/lib/screen/pages/talk/chatList.dart b/lib/screen/pages/talk/chatList.dart index a460ecc..65d1ad6 100644 --- a/lib/screen/pages/talk/chatList.dart +++ b/lib/screen/pages/talk/chatList.dart @@ -24,10 +24,6 @@ class _ChatListState extends State { void initState() { super.initState(); - Timer.periodic(const Duration(minutes: 1), (timer) { - Provider.of(context, listen: false).run(); - }); - SharedPreferences.getInstance().then((value) => { username = value.getString("username")! });