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_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<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) {
setLoading(false);
return (false, 'something went wrong');
return (false, 'Something want wrong');
}
}
}

View File

@ -139,61 +139,66 @@ class CollectKycScreenState extends State<CollectKycScreen>
return ChangeNotifierProvider(
create: (context) => collectKycProvider,
child: Consumer<CollectKycProvider>(
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()))
],
),
),
);
}

View File

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

View File

@ -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<String, List<Notifications>> 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<Notifications> 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 ?? ''),
),
),
);
},
);
),
],
),
);
},
);
}
}

View File

@ -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 ?? ''),

View File

@ -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';
}