From a41f500aee7b3a579e94a8944682810ff890a4fd Mon Sep 17 00:00:00 2001 From: kratikpal Date: Mon, 12 Aug 2024 09:50:34 +0530 Subject: [PATCH] notification screeen upgrade --- lib/provider/login_provider.dart | 20 +--- lib/screens/collect_kyc_screen.dart | 111 ++++++++++--------- lib/screens/login_screen.dart | 1 - lib/screens/notification_screen.dart | 92 ++++++++------- lib/screens/rejected_application_screen.dart | 2 +- lib/services/api_urls.dart | 1 + 6 files changed, 118 insertions(+), 109 deletions(-) diff --git a/lib/provider/login_provider.dart b/lib/provider/login_provider.dart index fa2622a..fd032f1 100644 --- a/lib/provider/login_provider.dart +++ b/lib/provider/login_provider.dart @@ -1,9 +1,11 @@ +import 'package:cheminova/notification_service.dart'; import 'package:cheminova/services/api_client.dart'; import 'package:cheminova/services/api_urls.dart'; import 'package:cheminova/services/secure__storage_service.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; + class LoginProvider extends ChangeNotifier { final _storageService = SecureStorageService(); @@ -31,26 +33,16 @@ class LoginProvider extends ChangeNotifier { if (response.statusCode == 200) { await _storageService.write( key: 'access_token', value: response.data['token']); + final fcmToken = await NotificationServices().getDeviceToken(); + print('fcmToken: $fcmToken'); + await _apiClient.post(ApiUrls.fcmUrl, data: {'fcmToken': fcmToken}); return (true, response.data['message'].toString()); } else { return (false, response.data['message'].toString()); } - } on DioException catch (e) { - setLoading(false); - - if (e.response?.data is Map) { - return ( - false, - e.response?.data['message'].toString() ?? 'something went wrong' - ); - } else if (e.response?.data is String) { - return (false, e.response?.data.toString() ?? 'something went wrong'); - } else { - return (false, 'something went wrong'); - } } catch (e) { setLoading(false); - return (false, 'something went wrong'); + return (false, 'Something want wrong'); } } } diff --git a/lib/screens/collect_kyc_screen.dart b/lib/screens/collect_kyc_screen.dart index a82529d..f8f2515 100644 --- a/lib/screens/collect_kyc_screen.dart +++ b/lib/screens/collect_kyc_screen.dart @@ -139,61 +139,66 @@ class CollectKycScreenState extends State return ChangeNotifierProvider( create: (context) => collectKycProvider, child: Consumer( - builder: (BuildContext context, value, Widget? child) => - Stack(children: [ - CommonBackground( + builder: (BuildContext context, value, Widget? child) => Stack( + children: [ + CommonBackground( child: DefaultTabController( - length: 3, - child: Scaffold( + length: 3, + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: PreferredSize( + preferredSize: const Size.fromHeight(100), + child: CommonAppBar( + actions: [ + IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: Image.asset('assets/Back_attendance.png'), + padding: const EdgeInsets.only(right: 20), + ), + ], + title: const Text('Collect KYC Data', + style: TextStyle( + fontSize: 20, + color: Colors.black, + fontWeight: FontWeight.w400, + fontFamily: 'Anek')), backgroundColor: Colors.transparent, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(100), - child: CommonAppBar( - actions: [ - IconButton( - onPressed: () { - Navigator.pop(context); - }, - icon: - Image.asset('assets/Back_attendance.png'), - padding: const EdgeInsets.only(right: 20), - ), - ], - title: const Text('Collect KYC Data', - style: TextStyle( - fontSize: 20, - color: Colors.black, - fontWeight: FontWeight.w400, - fontFamily: 'Anek')), - backgroundColor: Colors.transparent, - elevation: 0, - bottom: TabBar( - controller: value.tabController, - padding: const EdgeInsets.symmetric( - horizontal: 10), - dividerColor: Colors.transparent, - indicatorColor: Colors.yellow, - labelColor: Colors.white, - unselectedLabelColor: Colors.black, - indicatorSize: TabBarIndicatorSize.tab, - indicator: BoxDecoration( - color: Colors.blue, - borderRadius: BorderRadius.circular(10)), - tabs: const [ - Tab(text: 'Details'), - Tab(text: 'Documents'), - Tab(text: 'Verify') - ]))), - drawer: const CommonDrawer(), - body: TabBarView( - controller: value.tabController, - physics: const NeverScrollableScrollPhysics(), - children: _pages)))), - if (value.isLoading) - Container( - color: Colors.black.withOpacity(0.5), - child: const Center(child: CircularProgressIndicator())) - ]), + elevation: 0, + bottom: TabBar( + controller: value.tabController, + padding: const EdgeInsets.symmetric(horizontal: 10), + dividerColor: Colors.transparent, + indicatorColor: Colors.yellow, + labelColor: Colors.white, + unselectedLabelColor: Colors.black, + indicatorSize: TabBarIndicatorSize.tab, + indicator: BoxDecoration( + color: Colors.blue, + borderRadius: BorderRadius.circular(10)), + tabs: const [ + Tab(text: 'Details'), + Tab(text: 'Documents'), + Tab(text: 'Verify') + ], + ), + ), + ), + drawer: const CommonDrawer(), + body: TabBarView( + controller: value.tabController, + physics: const NeverScrollableScrollPhysics(), + children: _pages), + ), + ), + ), + if (value.isLoading) + Container( + color: Colors.black.withOpacity(0.5), + child: const Center(child: CircularProgressIndicator())) + ], + ), ), ); } diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index 5bec42f..020fe1b 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -106,7 +106,6 @@ class _LoginPageState extends State { builder: (context, value, child) => CommonTextFormField( controller: value.passwordController, - obscureText: true, validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your password'; diff --git a/lib/screens/notification_screen.dart b/lib/screens/notification_screen.dart index 86d1380..2219bd7 100644 --- a/lib/screens/notification_screen.dart +++ b/lib/screens/notification_screen.dart @@ -86,48 +86,60 @@ class MyListView extends StatelessWidget { @override Widget build(BuildContext context) { - return value.notificationList.isEmpty - ? const Center( - child: Text( - 'No Notifications', - style: TextStyle( - fontSize: 20, - color: Colors.white, - fontWeight: FontWeight.w500, - fontFamily: 'Anek', + // Group notifications by date + Map> groupedNotifications = {}; + + for (var notification in value.notificationList) { + String date = DateFormat("dd MMM yyyy") + .format(DateTime.parse(notification.createdAt ?? '')); + if (!groupedNotifications.containsKey(date)) { + groupedNotifications[date] = []; + } + groupedNotifications[date]!.add(notification); + } + + return ListView.builder( + padding: const EdgeInsets.only(top: 15), + itemCount: groupedNotifications.length, + itemBuilder: (context, index) { + String date = groupedNotifications.keys.elementAt(index); + List notificationsForDate = groupedNotifications[date]!; + + return Padding( + padding: const EdgeInsets.only(bottom: 10, left: 10, right: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Display the date once + Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: Text( + date, + style: const TextStyle( + fontSize: 16, fontWeight: FontWeight.bold), + ), ), - ), - ) - : ListView.builder( - padding: const EdgeInsets.only(top: 15), - itemCount: value.notificationList.length, - itemBuilder: (context, index) { - Notifications item = value.notificationList[index]; - return Padding( - padding: const EdgeInsets.only(bottom: 10, left: 10, right: 10), - child: ExpansionTile( - collapsedBackgroundColor: Colors.white, - backgroundColor: Colors.white, - trailing: const SizedBox.shrink(), - title: Text( - item.title ?? '', - style: const TextStyle( - fontSize: 17, fontWeight: FontWeight.w500), - ), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - (DateFormat("dd/MMM/yyyy").format( - DateTime.parse(item.createdAt ?? ''), - )), - ), - Text(item.msg ?? ''), - ], + // Display notifications for the date + ...notificationsForDate.map( + (item) => Padding( + padding: const EdgeInsets.only(bottom: 10), + child: ExpansionTile( + collapsedBackgroundColor: Colors.white, + backgroundColor: Colors.white, + trailing: const SizedBox.shrink(), + title: Text( + item.title ?? '', + style: const TextStyle( + fontSize: 17, fontWeight: FontWeight.w500), + ), + subtitle: Text(item.msg ?? ''), ), ), - ); - }, - ); + ), + ], + ), + ); + }, + ); } } diff --git a/lib/screens/rejected_application_screen.dart b/lib/screens/rejected_application_screen.dart index abc96bb..bc771c5 100644 --- a/lib/screens/rejected_application_screen.dart +++ b/lib/screens/rejected_application_screen.dart @@ -104,7 +104,7 @@ class MyListView extends StatelessWidget { subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text((DateFormat("dd/MMMM/yyyy") + Text((DateFormat("dd MMMM yyyy") .format(DateTime.parse(item.createdAt ?? '')))), Text(item.sId ?? ''), for (var note in item.notes!) Text(note.message ?? ''), diff --git a/lib/services/api_urls.dart b/lib/services/api_urls.dart index 10a12b1..c8c9470 100644 --- a/lib/services/api_urls.dart +++ b/lib/services/api_urls.dart @@ -10,4 +10,5 @@ class ApiUrls { static const String getPdUrl = 'kyc/get-pd-tm'; static const String rejectedApplication = '${baseUrl}kyc/getAllrejected-tm'; static const String notificationUrl = '$baseUrl/get-notification-tm'; + static const String fcmUrl = '${baseUrl}kyc/save-fcm-tm'; }