741 lines
33 KiB
Dart
741 lines
33 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:jwt_decode/jwt_decode.dart';
|
|
import 'package:nhance_app_pwa/customAppBar/customAppBar.dart';
|
|
import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
import '../../customAppBar/customFooter.dart';
|
|
import '../../customAppBar/responsive.dart';
|
|
import '../../customAppBar/tabs.dart';
|
|
import '../../customAppBar/toastHelper.dart';
|
|
|
|
class claimtracklist extends StatefulWidget {
|
|
const claimtracklist({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<claimtracklist> createState() => _claimtracklistformState();
|
|
}
|
|
|
|
class _claimtracklistformState extends State<claimtracklist> {
|
|
late ApiService apiService;
|
|
dynamic _token;
|
|
bool isLoading = false;
|
|
dynamic empCodeString;
|
|
dynamic empPrimaryId;
|
|
dynamic client_id;
|
|
dynamic policyList;
|
|
dynamic policyDataIsEmpty = 1;
|
|
dynamic policyHeading;
|
|
dynamic policyName;
|
|
dynamic policyDate;
|
|
dynamic policyStatus;
|
|
dynamic policySubject;
|
|
dynamic policyNo;
|
|
dynamic hospitalName;
|
|
dynamic admitDate;
|
|
dynamic dischargeDate;
|
|
dynamic claimAmount;
|
|
dynamic member;
|
|
dynamic accidentDate;
|
|
dynamic departmentID;
|
|
dynamic EmployeePolicy;
|
|
List<Map<String, String>> employeeDetails = [];
|
|
dynamic argumentsData;
|
|
dynamic decodedToken;
|
|
dynamic claimTrackMsgList;
|
|
dynamic empName;
|
|
dynamic ticketID;
|
|
late TextEditingController messageController;
|
|
final Map<String, Color> statusColors = {
|
|
'Open': Colors.green,
|
|
'Answered': Colors.blue,
|
|
'Awaiting Reply': Colors.orange,
|
|
'Inprogress': Colors.yellow,
|
|
'Closed': Colors.red,
|
|
};
|
|
|
|
// Create a unique form key for each accordion section
|
|
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
apiService = ApiService(context); // Initialize ApiService here
|
|
_loadToken();
|
|
messageController = TextEditingController();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
messageController.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
dynamic arguments = ModalRoute.of(context)!.settings.arguments;
|
|
if (arguments != null && arguments is Map<String, dynamic>) {
|
|
argumentsData = arguments;
|
|
print('argumentsData');
|
|
print(argumentsData);
|
|
ticketID = argumentsData['id'];
|
|
claimTrackMsgList = argumentsData['message_list'];
|
|
departmentID = argumentsData['department_id'];
|
|
policyName = argumentsData['policy_name'];
|
|
policyStatus = argumentsData['status_value'];
|
|
policyNo = argumentsData['policy_no'];
|
|
policySubject = argumentsData['subject'];
|
|
policyDate = formatDateWithTime(argumentsData['date']);
|
|
claimAmount = argumentsData['claim_amount'];
|
|
member = argumentsData['member_name'];
|
|
if (departmentID == '3') {
|
|
accidentDate = argumentsData['accident_date'];
|
|
} else if (departmentID == '4') {
|
|
hospitalName = argumentsData['hospital_name'];
|
|
admitDate = argumentsData['admit_date'];
|
|
dischargeDate = argumentsData['discharge_date'];
|
|
}
|
|
print(claimTrackMsgList);
|
|
}
|
|
}
|
|
|
|
Future<void> _loadToken() async {
|
|
print('_loadToken');
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
final String? token = prefs.getString('token');
|
|
if (token != null && token.isNotEmpty) {
|
|
setState(() {
|
|
_token = token;
|
|
});
|
|
// Decode the JWT token received from the API response
|
|
decodedToken = Jwt.parseJwt(token);
|
|
print(decodedToken);
|
|
empName = decodedToken['name'];
|
|
empCodeString = prefs.getString('empCode');
|
|
print(empCodeString); // Check if emp_code is correct
|
|
empPrimaryId = prefs.getString('empPrimaryId');
|
|
client_id = prefs.getString('client_id');
|
|
print(client_id);
|
|
} else {
|
|
// Token is empty or null, handle accordingly (e.g., navigate to login screen)
|
|
// For now, let's navigate to the login screen
|
|
ToastHelper.showErrorToast(context, 'Session Out');
|
|
Navigator.pushReplacementNamed(context, 'login');
|
|
}
|
|
}
|
|
|
|
void sendClaimsMessage(Map<String, dynamic> formData) async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
try {
|
|
formData = formData.map((key, value) => MapEntry(key, value.toString()));
|
|
|
|
final response = await apiService.sendClaimsMessageToApi(formData);
|
|
|
|
if (response['success'] == 1) {
|
|
messageController.clear();
|
|
ToastHelper.showSuccessToast(context, 'Saved Successfully...');
|
|
messageController.clear();
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
Navigator.pushNamed(context, 'claims', arguments: 0);
|
|
print('Form data sent successfully.');
|
|
} else {
|
|
print('Failed to submit form data: ${response['status']}');
|
|
}
|
|
} catch (e) {
|
|
print('Error submitting form data: $e');
|
|
}
|
|
}
|
|
|
|
Color getStatusColor(String? policyStatus) {
|
|
if (policyStatus != null && statusColors.containsKey(policyStatus)) {
|
|
return statusColors[policyStatus]!;
|
|
} else {
|
|
return Color(0xFF000000); // Default color for policyStatus text
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: CustomAppBar(),
|
|
body: Stack(children: [
|
|
SingleChildScrollView(
|
|
child: Container(
|
|
padding: Responsive.isDesktop(context)
|
|
? EdgeInsets.symmetric(
|
|
horizontal: MediaQuery.of(context).size.width *
|
|
0.2, // 30% of screen width as horizontal padding
|
|
vertical: MediaQuery.of(context).size.height *
|
|
0.03, // 5% of screen height as vertical padding
|
|
)
|
|
: EdgeInsets.all(10),
|
|
color: Colors.white,
|
|
child: Column(children: [
|
|
Card(
|
|
elevation: 5,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius:
|
|
BorderRadius.circular(15.0), // Set border radius here
|
|
),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white, // Set background color to white
|
|
borderRadius: BorderRadius.circular(
|
|
15.0), // Set border radius for Container
|
|
),
|
|
padding: Responsive.isDesktop(context)
|
|
? EdgeInsets.only(top: 15, bottom: 15, left: 15, right: 15)
|
|
: EdgeInsets.only(
|
|
top: 10,
|
|
bottom: 10,
|
|
left: 10,
|
|
right: 10), // Add padding to the container
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
flex: 12,
|
|
child: Container(
|
|
alignment: Alignment.centerLeft,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Color(
|
|
0xFFFFFCE5), // Set background color for the container
|
|
borderRadius: BorderRadius.circular(
|
|
10), // Set border radius for the container
|
|
),
|
|
padding: Responsive.isDesktop(context)
|
|
? EdgeInsets.only(
|
|
top: 20,
|
|
bottom: 20,
|
|
left: 10,
|
|
right: 10)
|
|
: EdgeInsets.only(
|
|
top: 10,
|
|
bottom: 10,
|
|
left: 10,
|
|
right: 10),
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
flex: 1,
|
|
child: InkWell(
|
|
onTap: () {
|
|
Navigator.pushNamed(
|
|
context, 'claims');
|
|
},
|
|
child: Icon(
|
|
Icons
|
|
.chevron_left, // Replace with your desired icon
|
|
color: Color(0xFF000000),
|
|
size: 30,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: 11,
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
Responsive.isDesktop(context)
|
|
? MainAxisAlignment.center
|
|
: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
policyName ?? '',
|
|
textAlign: TextAlign.start,
|
|
style: GoogleFonts.poppins(
|
|
fontSize:
|
|
Responsive.isDesktop(
|
|
context)
|
|
? 20
|
|
: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF000000),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: Responsive.isDesktop(context)
|
|
? 20
|
|
: 20), // Space between rows
|
|
Column(
|
|
children: [
|
|
Responsive.isDesktop(context)
|
|
? buildDesktopLayout(context)
|
|
: buildMobileLayout(context)
|
|
],
|
|
), // Space between rows
|
|
// Add more rows as needed
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 15),
|
|
Container(
|
|
child: SingleChildScrollView(
|
|
child: Column(children: [
|
|
...claimTrackMsgList
|
|
.map<Widget>((message) {
|
|
bool isUserMessage =
|
|
message['staff_name'] == null;
|
|
String messageContent =
|
|
message['message'];
|
|
String messageDate = message['date'];
|
|
dynamic messagername;
|
|
if (isUserMessage) {
|
|
messagername = empName;
|
|
} else {
|
|
messagername = message['staff_name'];
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 4.0),
|
|
child: Align(
|
|
alignment: isUserMessage
|
|
? Alignment.centerLeft
|
|
: Alignment.centerLeft,
|
|
child: Container(
|
|
constraints:
|
|
BoxConstraints(maxWidth: 800),
|
|
padding: EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: isUserMessage
|
|
? Colors.blue[100]
|
|
: Colors.green[100],
|
|
borderRadius:
|
|
BorderRadius.circular(10),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
messageContent,
|
|
style: GoogleFonts.poppins(
|
|
fontSize:
|
|
Responsive.isDesktop(
|
|
context)
|
|
? 14
|
|
: 12,
|
|
fontWeight:
|
|
FontWeight.w400,
|
|
color: Color(0xFF000000),
|
|
),
|
|
),
|
|
SizedBox(height: 5),
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment
|
|
.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.person,
|
|
color: Color(
|
|
0xFFE26728),
|
|
size: 15,
|
|
),
|
|
SizedBox(width: 5),
|
|
Text(
|
|
messagername,
|
|
style: GoogleFonts
|
|
.poppins(
|
|
fontSize: Responsive
|
|
.isDesktop(
|
|
context)
|
|
? 16
|
|
: 14,
|
|
fontWeight:
|
|
FontWeight
|
|
.w500,
|
|
color: Color(
|
|
0xFF000000),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
formatDateWithTime(
|
|
messageDate),
|
|
style:
|
|
GoogleFonts.poppins(
|
|
fontSize: Responsive
|
|
.isDesktop(
|
|
context)
|
|
? 12
|
|
: 10,
|
|
fontWeight:
|
|
FontWeight.w400,
|
|
color:
|
|
Color(0xFF636363),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 8.0),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
flex: Responsive.isDesktop(
|
|
context)
|
|
? 10
|
|
: 9,
|
|
child: TextFormField(
|
|
controller: messageController,
|
|
onChanged: (value) => null,
|
|
decoration: InputDecoration(
|
|
border:
|
|
OutlineInputBorder(),
|
|
hintText: 'Message',
|
|
labelText: 'Message',
|
|
contentPadding:
|
|
EdgeInsets.symmetric(
|
|
vertical: 10,
|
|
horizontal: 15),
|
|
),
|
|
validator: (value) {
|
|
if (value == null ||
|
|
value.isEmpty) {
|
|
return 'Message is required';
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: Responsive.isDesktop(
|
|
context)
|
|
? 2
|
|
: 3,
|
|
child: Container(
|
|
alignment:
|
|
Alignment.centerRight,
|
|
child: ElevatedButton(
|
|
onPressed: () {
|
|
// Check if any of the fields are empty
|
|
if (messageController
|
|
.text.isEmpty) {
|
|
ToastHelper
|
|
.showWarningToast(
|
|
context,
|
|
'All fields are required');
|
|
} else {
|
|
// Create a map to hold the form data
|
|
Map<String, dynamic>
|
|
formData = {
|
|
'ticket_id': ticketID,
|
|
'replier': 'user',
|
|
'message':
|
|
messageController
|
|
.text,
|
|
// Add more form fields as needed
|
|
};
|
|
|
|
// Call the function to send form data to API
|
|
sendClaimsMessage(
|
|
formData);
|
|
}
|
|
},
|
|
child: Text(
|
|
'Reply',
|
|
style:
|
|
GoogleFonts.poppins(
|
|
color:
|
|
Colors.white),
|
|
),
|
|
style: ElevatedButton
|
|
.styleFrom(
|
|
backgroundColor:
|
|
Color(0xFFE26728),
|
|
shape:
|
|
RoundedRectangleBorder(
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(5),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)),
|
|
]),
|
|
),
|
|
),
|
|
],
|
|
))),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: Responsive.isDesktop(context) ? 40 : 10),
|
|
]),
|
|
)),
|
|
if (isLoading)
|
|
Container(
|
|
color: Color(0x98FFFCE5), // Semi-transparent background
|
|
child: Center(
|
|
child: // Your GIF loader widget
|
|
Image.asset(
|
|
height: 60,
|
|
width: 60,
|
|
'assets/nhance-loader.gif'), // Adjust path to your GIF loader
|
|
),
|
|
),
|
|
if (Responsive.isDesktop(context))
|
|
Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Container(
|
|
width: double.infinity, // Make the footer full width
|
|
child: CustomFooter(),
|
|
),
|
|
),
|
|
]),
|
|
floatingActionButton: Responsive.isDesktop(context)
|
|
? null
|
|
: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.pushNamed(context, 'chatbot');
|
|
},
|
|
child: Icon(Icons.chat),
|
|
),
|
|
floatingActionButtonLocation: Responsive.isDesktop(context)
|
|
? null
|
|
: FloatingActionButtonLocation.miniEndFloat,
|
|
bottomNavigationBar: Responsive.isDesktop(context)
|
|
? null
|
|
: CustomBottomNavigationBar(
|
|
onTabChanged: (index) {
|
|
if (index == 0) {
|
|
Navigator.pushNamed(context, 'home');
|
|
} else if (index == 1) {
|
|
Navigator.pushNamed(context, 'claims');
|
|
} else if (index == 2) {
|
|
Navigator.pushNamed(context, 'profile');
|
|
} else if (index == 3) {
|
|
Navigator.pushNamed(context, 'help');
|
|
} else if (index == 4) {
|
|
Navigator.pushNamed(context, 'wellness');
|
|
}
|
|
},
|
|
icons: [
|
|
Icons.home_outlined,
|
|
Icons.sticky_note_2_outlined,
|
|
Icons.person_outline_outlined,
|
|
Icons.headset_mic_outlined,
|
|
Icons.health_and_safety_outlined,
|
|
],
|
|
labels: [
|
|
"Home",
|
|
"Claim",
|
|
"Profile",
|
|
"Help",
|
|
"Wellness",
|
|
], // Initial index of the bottom navigation bar
|
|
),
|
|
);
|
|
}
|
|
|
|
String formatDateWithTime(String timestamp) {
|
|
// Convert the timestamp string to milliseconds
|
|
int milliseconds = int.parse(timestamp) * 1000;
|
|
|
|
// Create a DateTime object from milliseconds
|
|
DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds);
|
|
|
|
// Format the DateTime object with date and time
|
|
String formattedDate = DateFormat('d MMM, y HH:mm a').format(date);
|
|
|
|
return formattedDate;
|
|
}
|
|
|
|
Widget buildDesktopLayout(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// buildExpandedColumn(context, 'Policy No', policyNo),
|
|
buildExpandedColumn(context, 'Policy Name', policyName),
|
|
buildExpandedColumn(context, 'Status', policyStatus),
|
|
buildExpandedColumn(context, 'Subject', policySubject),
|
|
],
|
|
),
|
|
if (departmentID == '4') // Conditional check for policy_type
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Member', member),
|
|
buildExpandedColumn(context, 'Hospital Name', hospitalName),
|
|
buildExpandedColumn(context, 'Claim Amount', claimAmount),
|
|
],
|
|
),
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Admit Date', admitDate),
|
|
buildExpandedColumn(context, 'Discharge Date', dischargeDate),
|
|
buildExpandedColumn(context, '', ''),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
if (departmentID == '3') // Conditional check for policy_type
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Member', member),
|
|
buildExpandedColumn(context, 'Accident Date', accidentDate),
|
|
buildExpandedColumn(context, 'Claim Amount', claimAmount),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget buildMobileLayout(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Policy Name', policyName),
|
|
buildExpandedColumn(context, 'Status', policyStatus),
|
|
],
|
|
),
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Subject', policySubject),
|
|
buildExpandedColumn(context, 'Member', member),
|
|
],
|
|
),
|
|
if (departmentID == '4')
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Claim Amount', claimAmount),
|
|
buildExpandedColumn(context, 'Hospital Name', hospitalName),
|
|
],
|
|
),
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Admit Date', admitDate),
|
|
buildExpandedColumn(
|
|
context, 'Discharge Date', dischargeDate),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
if (departmentID == '3')
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildExpandedColumn(context, 'Claim Amount', claimAmount),
|
|
buildExpandedColumn(context, 'Accident Date', accidentDate),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildExpandedColumn(
|
|
BuildContext context, String title, String? value) {
|
|
return Expanded(
|
|
flex: 3,
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
title,
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.poppins(
|
|
fontSize: Responsive.isDesktop(context) ? 18 : 14,
|
|
fontWeight: FontWeight.w400,
|
|
color: Color(0xFF000000),
|
|
),
|
|
),
|
|
SizedBox(height: Responsive.isDesktop(context) ? 10 : 4),
|
|
title == 'Status'
|
|
? Text(
|
|
value ?? '', // Null check for value
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.poppins(
|
|
fontSize: Responsive.isDesktop(context) ? 18 : 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: getStatusColor(policyStatus),
|
|
),
|
|
)
|
|
: Text(
|
|
value ?? '', // Null check for value
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.poppins(
|
|
fontSize: Responsive.isDesktop(context) ? 18 : 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF000000),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|