diff --git a/lib/main.dart b/lib/main.dart index fa3ce51f..2a195e8b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,6 +42,7 @@ Future main() async { await Firebase.initializeApp(); await SharedPreferencesForDot.initializeSharedPreferences(); + await SharedPreferencesForDot.setNewNotificationDot(); await LocalNotificationService.localNotificationInit(); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); diff --git a/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart b/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart index 60bf6a1f..b9cfa6b7 100644 --- a/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart +++ b/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart @@ -310,14 +310,6 @@ class _GuideLinesScreenState extends State { SizedBox( height: size.height * 0.03, ), - InkWell( - onTap: LocalNotificationService.showNotification, - child: Container( - height: 100, - width: 100, - color: Colors.white, - ), - ), ], ), ) diff --git a/lib/new_ui/screens/main_screen/main_screen.dart b/lib/new_ui/screens/main_screen/main_screen.dart index 076666f8..df0c0e11 100644 --- a/lib/new_ui/screens/main_screen/main_screen.dart +++ b/lib/new_ui/screens/main_screen/main_screen.dart @@ -31,6 +31,8 @@ import 'package:tsec_app/new_ui/screens/committees_screen/old_committees_screen. import 'package:tsec_app/screens/tpc_screen.dart'; import 'package:url_launcher/link.dart'; +import '../../../services/sharedprefsfordot.dart'; + class MainScreen extends ConsumerStatefulWidget { const MainScreen({ Key? key, @@ -368,13 +370,18 @@ class _MainScreenState extends ConsumerState { Navigator.push(context, MaterialPageRoute(builder: ( context) => NotificationScreen(),),); }, - child: Padding( - padding: const EdgeInsets.fromLTRB(0, 6, 0, 0), - child: Image.asset( - 'assets/images/new_app_bar/icon_bell.png', - width: 45, - height: 45, - ), + child: Stack( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(0, 6, 0, 0), + child: Image.asset( + 'assets/images/new_app_bar/icon_bell.png', + width: 45, + height: 45, + ), + ), + (SharedPreferencesForDot.getNoOfNewNotification() - SharedPreferencesForDot.getNoOfNotification() != 0) ? Positioned(right: 0,top: 0,child: Container(alignment: Alignment.center,padding: EdgeInsets.all(6),decoration: BoxDecoration(color: Colors.red,shape: BoxShape.circle),child: Text("${SharedPreferencesForDot.getNoOfNewNotification() - SharedPreferencesForDot.getNoOfNotification()}",style: TextStyle(color: Colors.white,fontSize: 12),),),) : SizedBox(), + ], ), ), ), diff --git a/lib/screens/notification_screen/notification_screen.dart b/lib/screens/notification_screen/notification_screen.dart index 45111bfb..498fb4cf 100644 --- a/lib/screens/notification_screen/notification_screen.dart +++ b/lib/screens/notification_screen/notification_screen.dart @@ -6,6 +6,7 @@ import 'package:intl/intl.dart'; import 'package:tsec_app/provider/notification_provider.dart'; import 'package:tsec_app/screens/notification_screen/widgets/notification_list_item.dart'; import 'package:tsec_app/services/notification_service.dart'; +import 'package:tsec_app/services/sharedprefsfordot.dart'; import 'package:tsec_app/utils/custom_snackbar.dart'; import 'package:tsec_app/utils/init_get_it.dart'; import '../../models/notification_model/notification_model.dart'; @@ -29,6 +30,12 @@ class NotificationScreen extends ConsumerStatefulWidget { class _NotificationScreenState extends ConsumerState { DateTime _lastDate = DateTime(2000); + @override + void initState() { + super.initState(); + SharedPreferencesForDot.storeNoOfNotification(SharedPreferencesForDot.getNoOfNewNotification()); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -47,7 +54,7 @@ class _NotificationScreenState extends ConsumerState { final notifications = data.docs; return ListView.builder(itemCount: notifications.length, itemBuilder: (context, index){ final notif = NotificationModel.fromJson(notifications[index].data() as Map); - print(notif.attachments.toString()); + //print(notif.attachments.toString()); final listTile = NotificationListItem( notificationModel: notif, ); diff --git a/lib/services/sharedprefsfordot.dart b/lib/services/sharedprefsfordot.dart index 238f63c4..81154a56 100644 --- a/lib/services/sharedprefsfordot.dart +++ b/lib/services/sharedprefsfordot.dart @@ -1,4 +1,5 @@ import 'package:shared_preferences/shared_preferences.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; class SharedPreferencesForDot{ @@ -8,12 +9,29 @@ class SharedPreferencesForDot{ prefs = await SharedPreferences.getInstance(); } - static int getNotificationNumber(){ - return prefs.getInt("notificationNumber") ?? 0; + static setNewNotificationDot()async{ + final getDocs = await FirebaseFirestore.instance.collection("notifications").get(); + storeNoOfNewNotification(getDocs.docs.length); } - static storeNotificationNumber(int value){ - prefs.setInt("notificationNumber", value); + static int getNoOfNotification(){ + return prefs.getInt("noOfNotification") ?? 0; + } + + static storeNoOfNotification(int value){ + prefs.setInt("noOfNotification", value); + } + + static int getNoOfNewNotification(){ + return prefs.getInt("noOfNewNotification") ?? 0; + } + + static storeNoOfNewNotification(int value){ + prefs.setInt("noOfNewNotification", value); + } + + static makeNotificationEqual(){ + } static String getRailwayKeyStatus(){