Count and display Talk notifications in Appbar
This commit is contained in:
		
							
								
								
									
										36
									
								
								lib/app.dart
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								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) {
 | 
				
			||||||
 | 
					                  int messages = value.getRoomsResponse.data.map((e) => e.unreadMessages).reduce((a, b) => a+b);
 | 
				
			||||||
 | 
					                  return Visibility(
 | 
				
			||||||
 | 
					                    visible: messages > 0,
 | 
				
			||||||
                    child: Positioned(
 | 
					                    child: Positioned(
 | 
				
			||||||
                      right: 0,
 | 
					                      right: 0,
 | 
				
			||||||
 | 
					                      top: 0,
 | 
				
			||||||
                      child: Container(
 | 
					                      child: Container(
 | 
				
			||||||
                        padding: const EdgeInsets.all(1),
 | 
					                        padding: const EdgeInsets.all(1),
 | 
				
			||||||
                        decoration: BoxDecoration(
 | 
					                        decoration: BoxDecoration(
 | 
				
			||||||
                      color: Colors.red,
 | 
					                          color: Theme.of(context).primaryColor,
 | 
				
			||||||
                          borderRadius: BorderRadius.circular(6),
 | 
					                          borderRadius: BorderRadius.circular(6),
 | 
				
			||||||
                        ),
 | 
					                        ),
 | 
				
			||||||
                        constraints: const BoxConstraints(
 | 
					                        constraints: const BoxConstraints(
 | 
				
			||||||
                      minWidth: 12,
 | 
					                          minWidth: 13,
 | 
				
			||||||
                      minHeight: 12,
 | 
					                          minHeight: 13,
 | 
				
			||||||
                        ),
 | 
					                        ),
 | 
				
			||||||
                    child: const Text(
 | 
					                        child: Text(
 | 
				
			||||||
                      "1",
 | 
					                          "$messages",
 | 
				
			||||||
                      style: TextStyle(
 | 
					                          style: const TextStyle(
 | 
				
			||||||
                        color: Colors.black,
 | 
					                            color: Colors.white,
 | 
				
			||||||
                            fontSize: 10,
 | 
					                            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")!
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user