notification screeen upgrade

This commit is contained in:
kratikpal 2024-08-12 09:50:34 +05:30
parent 3e0e46d2b9
commit a41f500aee
6 changed files with 118 additions and 109 deletions

View File

@ -1,9 +1,11 @@
import 'package:cheminova/notification_service.dart';
import 'package:cheminova/services/api_client.dart'; import 'package:cheminova/services/api_client.dart';
import 'package:cheminova/services/api_urls.dart'; import 'package:cheminova/services/api_urls.dart';
import 'package:cheminova/services/secure__storage_service.dart'; import 'package:cheminova/services/secure__storage_service.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class LoginProvider extends ChangeNotifier { class LoginProvider extends ChangeNotifier {
final _storageService = SecureStorageService(); final _storageService = SecureStorageService();
@ -31,26 +33,16 @@ class LoginProvider extends ChangeNotifier {
if (response.statusCode == 200) { if (response.statusCode == 200) {
await _storageService.write( await _storageService.write(
key: 'access_token', value: response.data['token']); 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()); return (true, response.data['message'].toString());
} else { } else {
return (false, response.data['message'].toString()); return (false, response.data['message'].toString());
} }
} on DioException catch (e) {
setLoading(false);
if (e.response?.data is Map<String, dynamic>) {
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) { } catch (e) {
setLoading(false); setLoading(false);
return (false, 'something went wrong'); return (false, 'Something want wrong');
} }
} }
} }

View File

@ -139,8 +139,8 @@ class CollectKycScreenState extends State<CollectKycScreen>
return ChangeNotifierProvider( return ChangeNotifierProvider(
create: (context) => collectKycProvider, create: (context) => collectKycProvider,
child: Consumer<CollectKycProvider>( child: Consumer<CollectKycProvider>(
builder: (BuildContext context, value, Widget? child) => builder: (BuildContext context, value, Widget? child) => Stack(
Stack(children: [ children: [
CommonBackground( CommonBackground(
child: DefaultTabController( child: DefaultTabController(
length: 3, length: 3,
@ -154,8 +154,7 @@ class CollectKycScreenState extends State<CollectKycScreen>
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
icon: icon: Image.asset('assets/Back_attendance.png'),
Image.asset('assets/Back_attendance.png'),
padding: const EdgeInsets.only(right: 20), padding: const EdgeInsets.only(right: 20),
), ),
], ],
@ -169,8 +168,7 @@ class CollectKycScreenState extends State<CollectKycScreen>
elevation: 0, elevation: 0,
bottom: TabBar( bottom: TabBar(
controller: value.tabController, controller: value.tabController,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 10),
horizontal: 10),
dividerColor: Colors.transparent, dividerColor: Colors.transparent,
indicatorColor: Colors.yellow, indicatorColor: Colors.yellow,
labelColor: Colors.white, labelColor: Colors.white,
@ -183,17 +181,24 @@ class CollectKycScreenState extends State<CollectKycScreen>
Tab(text: 'Details'), Tab(text: 'Details'),
Tab(text: 'Documents'), Tab(text: 'Documents'),
Tab(text: 'Verify') Tab(text: 'Verify')
]))), ],
),
),
),
drawer: const CommonDrawer(), drawer: const CommonDrawer(),
body: TabBarView( body: TabBarView(
controller: value.tabController, controller: value.tabController,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
children: _pages)))), children: _pages),
),
),
),
if (value.isLoading) if (value.isLoading)
Container( Container(
color: Colors.black.withOpacity(0.5), color: Colors.black.withOpacity(0.5),
child: const Center(child: CircularProgressIndicator())) child: const Center(child: CircularProgressIndicator()))
]), ],
),
), ),
); );
} }

View File

@ -106,7 +106,6 @@ class _LoginPageState extends State<LoginPage> {
builder: (context, value, child) => builder: (context, value, child) =>
CommonTextFormField( CommonTextFormField(
controller: value.passwordController, controller: value.passwordController,
obscureText: true,
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Please enter your password'; return 'Please enter your password';

View File

@ -86,25 +86,43 @@ class MyListView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return value.notificationList.isEmpty // Group notifications by date
? const Center( Map<String, List<Notifications>> groupedNotifications = {};
child: Text(
'No Notifications', for (var notification in value.notificationList) {
style: TextStyle( String date = DateFormat("dd MMM yyyy")
fontSize: 20, .format(DateTime.parse(notification.createdAt ?? ''));
color: Colors.white, if (!groupedNotifications.containsKey(date)) {
fontWeight: FontWeight.w500, groupedNotifications[date] = [];
fontFamily: 'Anek', }
), groupedNotifications[date]!.add(notification);
), }
)
: ListView.builder( return ListView.builder(
padding: const EdgeInsets.only(top: 15), padding: const EdgeInsets.only(top: 15),
itemCount: value.notificationList.length, itemCount: groupedNotifications.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
Notifications item = value.notificationList[index]; String date = groupedNotifications.keys.elementAt(index);
List<Notifications> notificationsForDate = groupedNotifications[date]!;
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 10, left: 10, right: 10), 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),
),
),
// Display notifications for the date
...notificationsForDate.map(
(item) => Padding(
padding: const EdgeInsets.only(bottom: 10),
child: ExpansionTile( child: ExpansionTile(
collapsedBackgroundColor: Colors.white, collapsedBackgroundColor: Colors.white,
backgroundColor: Colors.white, backgroundColor: Colors.white,
@ -114,18 +132,12 @@ class MyListView extends StatelessWidget {
style: const TextStyle( style: const TextStyle(
fontSize: 17, fontWeight: FontWeight.w500), fontSize: 17, fontWeight: FontWeight.w500),
), ),
subtitle: Column( subtitle: Text(item.msg ?? ''),
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ ),
Text(
(DateFormat("dd/MMM/yyyy").format(
DateTime.parse(item.createdAt ?? ''),
)),
), ),
Text(item.msg ?? ''),
], ],
), ),
),
); );
}, },
); );

View File

@ -104,7 +104,7 @@ class MyListView extends StatelessWidget {
subtitle: Column( subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text((DateFormat("dd/MMMM/yyyy") Text((DateFormat("dd MMMM yyyy")
.format(DateTime.parse(item.createdAt ?? '')))), .format(DateTime.parse(item.createdAt ?? '')))),
Text(item.sId ?? ''), Text(item.sId ?? ''),
for (var note in item.notes!) Text(note.message ?? ''), for (var note in item.notes!) Text(note.message ?? ''),

View File

@ -10,4 +10,5 @@ class ApiUrls {
static const String getPdUrl = 'kyc/get-pd-tm'; static const String getPdUrl = 'kyc/get-pd-tm';
static const String rejectedApplication = '${baseUrl}kyc/getAllrejected-tm'; static const String rejectedApplication = '${baseUrl}kyc/getAllrejected-tm';
static const String notificationUrl = '$baseUrl/get-notification-tm'; static const String notificationUrl = '$baseUrl/get-notification-tm';
static const String fcmUrl = '${baseUrl}kyc/save-fcm-tm';
} }