Page Shaking
This commit is contained in:
parent
b88973d43c
commit
3e3ef56694
@ -13,6 +13,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../routes/custom_appBar.dart';
|
||||
import '../../routes/custom_drawer.dart';
|
||||
import '../../routes/mainLayout.dart';
|
||||
import '../../services/apiService.dart';
|
||||
import '../../utils/auth_utils.dart';
|
||||
import '../../utils/pagination.dart';
|
||||
@ -69,12 +70,15 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
print("allPlans before filtering: $allPlans");
|
||||
final lowerQuery = query.toLowerCase();
|
||||
setState(() {
|
||||
filteredPlans = allPlans.where((plan) {
|
||||
filteredPlans =
|
||||
allPlans.where((plan) {
|
||||
return (plan.planId?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.employeeCode?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.employeeCode?.toLowerCase().contains(lowerQuery) ??
|
||||
false) ||
|
||||
(plan.tripTitle?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.userName?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.travellerName?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.travellerName?.toLowerCase().contains(lowerQuery) ??
|
||||
false) ||
|
||||
(plan.tripType?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.createdOn?.toLowerCase().contains(lowerQuery) ?? false) ||
|
||||
(plan.statusValue?.toLowerCase().contains(lowerQuery) ?? false);
|
||||
@ -88,11 +92,13 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
|
||||
setState(() {
|
||||
layoutColor = layoutString != null
|
||||
layoutColor =
|
||||
layoutString != null
|
||||
? Color(int.parse(layoutString))
|
||||
: Colors.redAccent;
|
||||
|
||||
bodyColor = bodyStringColor != null
|
||||
bodyColor =
|
||||
bodyStringColor != null
|
||||
? Color(int.parse(bodyStringColor))
|
||||
: Colors.white;
|
||||
});
|
||||
@ -245,8 +251,10 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
}
|
||||
|
||||
void deletePlan(String planId) async {
|
||||
bool confirmed =
|
||||
await apiService.showCancelConfirmationDialog(context, layoutColor);
|
||||
bool confirmed = await apiService.showCancelConfirmationDialog(
|
||||
context,
|
||||
layoutColor,
|
||||
);
|
||||
|
||||
if (confirmed) {
|
||||
try {
|
||||
@ -263,35 +271,48 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFf5f5f5),
|
||||
// backgroundColor: Color(0xFFFCFCFC),
|
||||
|
||||
// appBar: isDesktop ? null : const CustomAppBar(title: 'Home'),
|
||||
// drawer: isDesktop ? null : CustomDrawer(isDesktop: false),
|
||||
appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
drawer: CustomDrawer(isDesktop: false),
|
||||
body: Padding(
|
||||
padding: isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width *
|
||||
0.1, // 30% of screen width as horizontal padding
|
||||
vertical: MediaQuery.of(context).size.height *
|
||||
0, // 5% of screen height as vertical padding
|
||||
)
|
||||
: EdgeInsets.all(0),
|
||||
return MainLayout(
|
||||
isDesktop: isDesktop,
|
||||
child: Row(
|
||||
children: [
|
||||
// if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
Expanded(child: buildGroupListLayout(isDesktop))
|
||||
Expanded(child: buildGroupListLayout(isDesktop)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
// return Scaffold(
|
||||
// backgroundColor: Color(0xFFf5f5f5),
|
||||
// // backgroundColor: Color(0xFFFCFCFC),
|
||||
// appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
// drawer: CustomDrawer(isDesktop: false),
|
||||
// body: Padding(
|
||||
// padding:
|
||||
// isDesktop
|
||||
// ? EdgeInsets.symmetric(
|
||||
// horizontal:
|
||||
// MediaQuery.of(context).size.width *
|
||||
// 0.1, // 30% of screen width as horizontal padding
|
||||
// vertical:
|
||||
// MediaQuery.of(context).size.height *
|
||||
// 0, // 5% of screen height as vertical padding
|
||||
// )
|
||||
// : EdgeInsets.all(0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// // if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
// Expanded(child: buildGroupListLayout(isDesktop)),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildGroupListLayout(bool isDesktop) {
|
||||
@ -322,8 +343,9 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
String _formatDate(String rawDate) {
|
||||
try {
|
||||
final dateTime = DateTime.parse(rawDate);
|
||||
return DateFormat('dd, MMM yyyy HH:mm')
|
||||
.format(dateTime); // 24-hour format
|
||||
return DateFormat(
|
||||
'dd, MMM yyyy HH:mm',
|
||||
).format(dateTime); // 24-hour format
|
||||
} catch (e) {
|
||||
return rawDate; // fallback if parsing fails
|
||||
}
|
||||
@ -332,11 +354,13 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
return Container(
|
||||
margin: isDesktop ? EdgeInsets.all(10.0) : null,
|
||||
padding: const EdgeInsets.only(top: 15, bottom: 15, left: 20, right: 20),
|
||||
height: isDesktop
|
||||
height:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.height * 0.98
|
||||
: MediaQuery.of(context).size.height,
|
||||
decoration: BoxDecoration(
|
||||
border: isDesktop
|
||||
border:
|
||||
isDesktop
|
||||
? Border.all(
|
||||
width: 2,
|
||||
color: Colors.white,
|
||||
@ -382,9 +406,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: 1,
|
||||
),
|
||||
SizedBox(width: 1),
|
||||
Spacer(),
|
||||
if (isDesktop)
|
||||
Container(
|
||||
@ -395,8 +417,10 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
onChanged: filterPlans,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search...",
|
||||
hintStyle:
|
||||
TextStyle(fontSize: 12, color: Color(0xFF9E9DBD)),
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF9E9DBD),
|
||||
),
|
||||
prefixIcon: Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF9E9DBD),
|
||||
@ -408,22 +432,23 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade200, width: 0.5),
|
||||
color: Colors.grey.shade200,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade300, width: 1),
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
),
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
),
|
||||
|
||||
// SizedBox(width: 16),
|
||||
|
||||
Spacer(),
|
||||
// ElevatedButton(
|
||||
// style: ElevatedButton.styleFrom(
|
||||
@ -521,8 +546,10 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
onChanged: filterPlans,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search...",
|
||||
hintStyle:
|
||||
TextStyle(fontSize: 12, color: Color(0xFF9E9DBD)),
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF9E9DBD),
|
||||
),
|
||||
prefixIcon: Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF9E9DBD),
|
||||
@ -534,17 +561,19 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade200, width: 0.5),
|
||||
color: Colors.grey.shade200,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade300, width: 1),
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
),
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -581,14 +610,17 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black54),
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Please Create Trip",
|
||||
textAlign: TextAlign.center,
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12, color: Colors.grey),
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -604,10 +636,13 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
List<Plan> plans =
|
||||
searchController.text.isEmpty ? allPlans : filteredPlans;
|
||||
|
||||
plans.sort((a, b) =>
|
||||
int.parse(b.planId).compareTo(int.parse(a.planId)));
|
||||
plans.sort(
|
||||
(a, b) =>
|
||||
int.parse(b.planId).compareTo(int.parse(a.planId)),
|
||||
);
|
||||
|
||||
List<Plan> paginatedPlans = plans
|
||||
List<Plan> paginatedPlans =
|
||||
plans
|
||||
.skip(currentPage * itemsPerPage)
|
||||
.take(itemsPerPage)
|
||||
.toList();
|
||||
@ -623,112 +658,169 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
columnSpacing: isDesktop ? 24.0 : 16.0,
|
||||
border: TableBorder(
|
||||
horizontalInside: BorderSide(
|
||||
width: 0.5, color: Colors.grey.shade200),
|
||||
width: 0.5,
|
||||
color: Colors.grey.shade200,
|
||||
),
|
||||
),
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Trip ID',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Trip Name',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Emp Code',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Traveller',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Trip Type',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Created On',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Status',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
'Actions',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13, fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: paginatedPlans.map((plan) {
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(plan.planId,
|
||||
rows:
|
||||
paginatedPlans.map((plan) {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(
|
||||
Text(
|
||||
plan.planId,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
DataCell(Text(plan.tripTitle,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
plan.tripTitle,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis)),
|
||||
DataCell(Text(plan.employeeCode ?? " - ",
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
plan.employeeCode ?? " - ",
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
DataCell(Text(
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
plan.userName.isNotEmpty
|
||||
? plan.userName
|
||||
: plan.travellerName,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
DataCell(Text(plan.tripType,
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
plan.tripType,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
DataCell(Text(_formatDate(plan.createdOn),
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
_formatDate(plan.createdOn),
|
||||
// plan.createdOn,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Container(
|
||||
width: double
|
||||
width:
|
||||
double
|
||||
.infinity, // Set your desired fixed size (equal width and height)
|
||||
height: 25,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: getStatusColor(plan.statusValue),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: getStatusColor(
|
||||
plan.statusValue,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(
|
||||
10,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
plan.statusValue,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color:
|
||||
getStatusTextColor(plan.statusValue),
|
||||
color: getStatusTextColor(
|
||||
plan.statusValue,
|
||||
),
|
||||
fontSize: 12,
|
||||
fontFamily: "Inter",
|
||||
fontWeight: FontWeight.w400,
|
||||
@ -748,84 +840,130 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
color: Color(0xFF475569),
|
||||
size: 14,
|
||||
),
|
||||
itemBuilder: (context) => [
|
||||
itemBuilder:
|
||||
(context) => [
|
||||
CustomPopupMenuEntry(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 8),
|
||||
padding:
|
||||
EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisSize:
|
||||
MainAxisSize.min,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
MainAxisAlignment
|
||||
.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_red_eye,
|
||||
color: Color(0xFF475569),
|
||||
size: 18),
|
||||
tooltip: 'View Trips',
|
||||
Icons
|
||||
.remove_red_eye,
|
||||
color: Color(
|
||||
0xFF475569,
|
||||
),
|
||||
size: 18,
|
||||
),
|
||||
tooltip:
|
||||
'View Trips',
|
||||
onPressed: () {
|
||||
Navigator.pop(
|
||||
context); // Close popup manually
|
||||
context,
|
||||
); // Close popup manually
|
||||
ApiService.viewPlan(
|
||||
context, plan.planId,
|
||||
isViewMode: true);
|
||||
context,
|
||||
plan.planId,
|
||||
isViewMode:
|
||||
true,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Image.asset(
|
||||
'assets/images/IconsImg/edit.png',
|
||||
width: 20,
|
||||
height: 15),
|
||||
height: 15,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(
|
||||
context,
|
||||
);
|
||||
ApiService.viewPlan(
|
||||
context, plan.planId,
|
||||
isViewMode: false);
|
||||
context,
|
||||
plan.planId,
|
||||
isViewMode:
|
||||
false,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.cancel_rounded,
|
||||
size: 18),
|
||||
tooltip: 'Cancellation Trips',
|
||||
Icons
|
||||
.cancel_rounded,
|
||||
size: 18,
|
||||
),
|
||||
tooltip:
|
||||
'Cancellation Trips',
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
deletePlan(plan.planId);
|
||||
Navigator.pop(
|
||||
context,
|
||||
);
|
||||
deletePlan(
|
||||
plan.planId,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.download,
|
||||
color: Color(0xFF114D8B),
|
||||
size: 18),
|
||||
tooltip: 'Download Trips Detials',
|
||||
icon: Icon(
|
||||
Icons.download,
|
||||
color: Color(
|
||||
0xFF114D8B,
|
||||
),
|
||||
size: 18,
|
||||
),
|
||||
tooltip:
|
||||
'Download Trips Detials',
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
apiService.getPdfDownload(
|
||||
plan.planId);
|
||||
Navigator.pop(
|
||||
context,
|
||||
);
|
||||
apiService
|
||||
.getPdfDownload(
|
||||
plan.planId,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.comment,
|
||||
color: Color(0xFF475569),
|
||||
color: Color(
|
||||
0xFF475569,
|
||||
),
|
||||
size: 11,
|
||||
),
|
||||
tooltip: 'Trips Comments',
|
||||
tooltip:
|
||||
'Trips Comments',
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CommentModalList(
|
||||
context:
|
||||
context,
|
||||
builder:
|
||||
(
|
||||
context,
|
||||
) => CommentModalList(
|
||||
// planId: plan.planId,
|
||||
planId: plan
|
||||
.planId
|
||||
planId:
|
||||
plan.planId
|
||||
.toString(),
|
||||
layoutColorForUser:
|
||||
layoutColor!,
|
||||
role: "Admin"),
|
||||
role:
|
||||
"Admin",
|
||||
),
|
||||
);
|
||||
}),
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -835,7 +973,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
],
|
||||
),
|
||||
),
|
||||
]);
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
@ -849,8 +988,10 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
final plan = paginatedPlans[index];
|
||||
return Card(
|
||||
color: Colors.white,
|
||||
margin:
|
||||
EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@ -875,18 +1016,23 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 4),
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: getStatusColor(
|
||||
plan.statusValue),
|
||||
borderRadius:
|
||||
BorderRadius.circular(8),
|
||||
plan.statusValue,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(
|
||||
8,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
plan.statusValue,
|
||||
style: TextStyle(
|
||||
color: getStatusTextColor(
|
||||
plan.statusValue),
|
||||
plan.statusValue,
|
||||
),
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@ -915,11 +1061,14 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(' ${plan.tripTitle}',
|
||||
Text(
|
||||
' ${plan.tripTitle}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontFamily: "Inter",
|
||||
fontWeight: FontWeight.bold)),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@ -934,24 +1083,28 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(' ${plan.tripType}',
|
||||
Text(
|
||||
' ${plan.tripType}',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: Colors.black87,
|
||||
fontFamily: "Inter",
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${_formatDate(plan.createdOn)}',
|
||||
Text(
|
||||
'${_formatDate(plan.createdOn)}',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: Colors.black87,
|
||||
fontFamily: "Inter",
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@ -971,7 +1124,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontFamily: "Inter",
|
||||
color: Colors.black87),
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -985,7 +1139,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontFamily: "Inter",
|
||||
color: Colors.black87),
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -1005,14 +1160,17 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: isDesktop
|
||||
child:
|
||||
isDesktop
|
||||
? (searchController.text.isNotEmpty &&
|
||||
filteredPlans.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
"No matches found",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14, color: Colors.grey),
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
@ -1025,7 +1183,9 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
child: Text(
|
||||
"No matches found",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14, color: Colors.grey),
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: buildMobileCardView(paginatedPlans)),
|
||||
@ -1058,7 +1218,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<dynamic> showApprovalDialog(
|
||||
BuildContext context, Color layoutColor) async {
|
||||
BuildContext context,
|
||||
Color layoutColor,
|
||||
) async {
|
||||
String selectedAction = ""; // "", "accept", "reject"
|
||||
String remarks = "";
|
||||
|
||||
@ -24,13 +26,12 @@ Future<dynamic> showApprovalDialog(
|
||||
Text(
|
||||
"To Approve or Reject Trip",
|
||||
style: TextStyle(
|
||||
fontFamily: "Inter", fontWeight: FontWeight.w500),
|
||||
fontFamily: "Inter",
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
size: 15,
|
||||
),
|
||||
icon: const Icon(Icons.close, size: 15),
|
||||
onPressed: () {
|
||||
Navigator.pop(context, null); // Close the dialog
|
||||
},
|
||||
@ -45,10 +46,12 @@ Future<dynamic> showApprovalDialog(
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: selectedAction == "accept"
|
||||
? layoutColor
|
||||
backgroundColor:
|
||||
selectedAction == "accept"
|
||||
? Colors.green
|
||||
: Colors.grey.shade200,
|
||||
foregroundColor: selectedAction == "accept"
|
||||
foregroundColor:
|
||||
selectedAction == "accept"
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
shape: RoundedRectangleBorder(
|
||||
@ -68,10 +71,12 @@ Future<dynamic> showApprovalDialog(
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: selectedAction == "reject"
|
||||
backgroundColor:
|
||||
selectedAction == "reject"
|
||||
? Colors.redAccent
|
||||
: Colors.grey.shade200,
|
||||
foregroundColor: selectedAction == "reject"
|
||||
foregroundColor:
|
||||
selectedAction == "reject"
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
shape: RoundedRectangleBorder(
|
||||
@ -122,12 +127,16 @@ Future<dynamic> showApprovalDialog(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(
|
||||
color: Colors.blueGrey, width: 0.5),
|
||||
color: Colors.blueGrey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
BorderSide(color: Colors.blueGrey, width: 0.5),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.blueGrey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@ -135,7 +144,7 @@ Future<dynamic> showApprovalDialog(
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
],
|
||||
],
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
@ -187,14 +196,12 @@ Future<dynamic> showApprovalDialog(
|
||||
Future<bool?> showApproveDialog1(BuildContext context, Color layoutColor) {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
title: const Text(
|
||||
"Confirm Approval",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
content: const Text("Are you sure you want to approve this plan?"),
|
||||
actions: [
|
||||
@ -231,14 +238,17 @@ Future<bool?> showApproveDialog1(BuildContext context, Color layoutColor) {
|
||||
|
||||
/// Show confirm dialog for rejection with remarks input
|
||||
Future<String?> showRejectDialog1(
|
||||
BuildContext context, Color layoutColor) async {
|
||||
BuildContext context,
|
||||
Color layoutColor,
|
||||
) async {
|
||||
String remarks = "";
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) => AlertDialog(
|
||||
builder:
|
||||
(context, setState) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
contentPadding: const EdgeInsets.all(36),
|
||||
// title: const Text("Confirm Rejection"),
|
||||
@ -260,13 +270,20 @@ Future<String?> showRejectDialog1(
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 10, // 👈 Set your desired font size here
|
||||
color: Colors.grey,
|
||||
fontFamily: "Inter", // optional if you want consistent font
|
||||
fontFamily:
|
||||
"Inter", // optional if you want consistent font
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.blueGrey, width: 0.5),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.blueGrey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.blueGrey, width: 0.5),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.blueGrey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 1),
|
||||
|
||||
@ -11,6 +11,8 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../services/apiService.dart';
|
||||
|
||||
class LoginWidget extends StatefulWidget {
|
||||
final bool isDesktop;
|
||||
final bool isTablet;
|
||||
@ -25,6 +27,9 @@ class LoginWidget extends StatefulWidget {
|
||||
enum LoginStep { login, forgotEmail, otpReset }
|
||||
|
||||
class _LoginWidgetState extends State<LoginWidget> {
|
||||
final ApiService apiService = ApiService();
|
||||
bool _moved = false;
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
@ -39,6 +44,17 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
// 🔹 Login Step Enum and State Variable
|
||||
LoginStep _loginStep = LoginStep.login;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
Future.delayed(Duration(milliseconds: 300), () {
|
||||
setState(() {
|
||||
_moved = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
@ -54,15 +70,18 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
final parts = token.split('.');
|
||||
if (parts.length != 3) throw Exception('Invalid token format');
|
||||
|
||||
final payload = json
|
||||
.decode(utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))));
|
||||
final payload = json.decode(
|
||||
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))),
|
||||
);
|
||||
|
||||
final userData = payload['data'];
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('auth_token', token);
|
||||
await prefs.setString(
|
||||
'user_data', jsonEncode(userData)); // Store full user data
|
||||
'user_data',
|
||||
jsonEncode(userData),
|
||||
); // Store full user data
|
||||
|
||||
if (userData != null) {
|
||||
final pref = await SharedPreferences.getInstance();
|
||||
@ -75,6 +94,8 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
print("userData11 - ${userData['role']}");
|
||||
print("userData12 - $userRole");
|
||||
}
|
||||
|
||||
apiService.getOrganizationData();
|
||||
} catch (e) {
|
||||
print('Error decoding token: $e');
|
||||
}
|
||||
@ -89,7 +110,7 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'email': _emailController.text.trim(),
|
||||
@ -145,9 +166,9 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
// );
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Error: $e")),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text("Error: $e")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,19 +196,27 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
// _clearAllFields();
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("OTP sent to your email")),
|
||||
SnackBar(
|
||||
content: Text("OTP sent to your email"),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print(response);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text("${jsonDecode(response.body)['messages']['error']}")),
|
||||
content: Text(
|
||||
"${jsonDecode(response.body)['messages']['error']}",
|
||||
),
|
||||
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text("Error: $e")));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Error: $e"), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
} else if (!_isForgotPassword && _showOtpResetFields) {
|
||||
print('22');
|
||||
@ -214,20 +243,32 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
_clearAllFields();
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Password reset successfully")),
|
||||
SnackBar(
|
||||
content: Text("Password reset successfully"),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('23');
|
||||
print('otp wrong');
|
||||
final responseBody = json.decode(response.body);
|
||||
final errorMessage =
|
||||
responseBody['messages']?['error'] ?? 'An unknown error occurred';
|
||||
print(errorMessage);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"Reset failed: ${jsonDecode(response.body)['message']}")),
|
||||
"Reset failed: $errorMessage",
|
||||
// "Reset failed: ${jsonDecode(response.body)['message']}",
|
||||
),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text("Error: $e")));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Error: $e"), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Login flow
|
||||
@ -255,15 +296,15 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
/// Layout
|
||||
Widget build(BuildContext context) {
|
||||
double formWidth = widget.isTablet ? 400 : 300;
|
||||
|
||||
return Container(
|
||||
// color: Color(0xFF114D8B),
|
||||
color: Color(0xFFf5f5f5),
|
||||
color: Colors.white,
|
||||
|
||||
// color: Color(0xFFf5f5f5),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: [
|
||||
@ -285,8 +326,9 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
// color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(250), // Rounded top-left corner
|
||||
bottomRight:
|
||||
Radius.circular(250), // Rounded bottom-left corner
|
||||
bottomRight: Radius.circular(
|
||||
250,
|
||||
), // Rounded bottom-left corner
|
||||
),
|
||||
),
|
||||
// child: Padding(
|
||||
@ -305,11 +347,15 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/login/logoNew.jpg',
|
||||
// Image.asset(
|
||||
// 'assets/images/login/logoNew.jpg',
|
||||
// width: 200, // Optional: control size
|
||||
// height: 100,
|
||||
// fit: BoxFit.contain,
|
||||
// ),
|
||||
Container(
|
||||
width: 200, // Optional: control size
|
||||
height: 100,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
@ -320,9 +366,10 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
// width: 200, // Optional: control size
|
||||
// height: 100,
|
||||
fit: BoxFit.contain,
|
||||
)),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -332,20 +379,18 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
// color: Colors.white,
|
||||
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(25), // Rounded top-left corner
|
||||
bottomLeft: Radius.circular(25), // Rounded bottom-left corner
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(40),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: _buildForm(width: formWidth), // Fixed form width
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -353,29 +398,57 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
|
||||
/// **Reusable Login Form**
|
||||
Widget _buildForm({required double width}) {
|
||||
return SizedBox(
|
||||
return Column(
|
||||
children: [
|
||||
// width: width,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/login/logoNew.jpg',
|
||||
width: 180, // Optional: control size
|
||||
height: 70,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: width,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
"Sign In",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF212121)),
|
||||
fontSize: widget.isDesktop ? 20 : 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.green,
|
||||
// color: Color(0xFF212121),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
"Welcome To TripApprovalTool",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Color(0xFF212121)),
|
||||
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
/// **Email Field**
|
||||
if (!_isForgotPassword && !_showOtpResetFields) ...[
|
||||
@ -383,47 +456,61 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
decoration:
|
||||
_inputDecoration("Enter your email address").copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
decoration: _inputDecoration(
|
||||
"Enter your email address",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.email_outlined,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? 'Required Email' : null,
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required Email'
|
||||
: null,
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
/// **Password Field**
|
||||
_buildLabel("Password"),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
obscureText: _obscureText,
|
||||
decoration: _inputDecoration("Enter your password").copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.key,
|
||||
size: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
obscureText: _obscureText,
|
||||
decoration: _inputDecoration(
|
||||
"Enter your password",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(Icons.key, size: 16),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||
_obscureText
|
||||
? Icons.visibility_off
|
||||
: Icons.visibility,
|
||||
color: Color(0xFF12B24B),
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () =>
|
||||
setState(() => _obscureText = !_obscureText),
|
||||
onPressed:
|
||||
() => setState(
|
||||
() => _obscureText = !_obscureText,
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? 'Required Password' : null,
|
||||
),
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required Password'
|
||||
: null,
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
/// **Login Button**
|
||||
Row(
|
||||
@ -432,31 +519,39 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _login(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF12B24B), // Button color
|
||||
foregroundColor: Colors.white, // Text color
|
||||
backgroundColor: Color(
|
||||
0xFF12B24B,
|
||||
), // Button color
|
||||
foregroundColor:
|
||||
Colors.white, // Text color
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 12),
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18)),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 10),
|
||||
horizontal: 24,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Sign In",
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w800, fontSize: 15),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 13.5,
|
||||
),
|
||||
SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
SizedBox(width: 3),
|
||||
Icon(
|
||||
Icons.arrow_forward_sharp,
|
||||
color: Colors.white,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -464,54 +559,69 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
),
|
||||
],
|
||||
),
|
||||
] else if (_isForgotPassword && !_showOtpResetFields) ...[
|
||||
] else if (_isForgotPassword &&
|
||||
!_showOtpResetFields) ...[
|
||||
_buildLabel("Email Address"),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
decoration:
|
||||
_inputDecoration("Enter your email address").copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
decoration: _inputDecoration(
|
||||
"Enter your email address",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.email_outlined,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? 'Required Email' : null,
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required Email'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _onSubmit(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF12B24B), // Button color
|
||||
foregroundColor: Colors.white, // Text color
|
||||
backgroundColor: Color(
|
||||
0xFF12B24B,
|
||||
), // Button color
|
||||
foregroundColor:
|
||||
Colors.white, // Text color
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 12),
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18)),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 10),
|
||||
horizontal: 24,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Submit",
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w800, fontSize: 15),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 13.5,
|
||||
),
|
||||
SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
SizedBox(width: 3),
|
||||
Icon(
|
||||
Icons.arrow_forward_sharp,
|
||||
color: Colors.white,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -525,80 +635,103 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
controller: _emailController,
|
||||
readOnly: true,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
decoration:
|
||||
_inputDecoration("Enter your email address").copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
decoration: _inputDecoration(
|
||||
"Enter your email address",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.email_outlined,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? 'Required Email' : null,
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required Email'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 10),
|
||||
_buildLabel("OTP"),
|
||||
TextFormField(
|
||||
controller: _otpController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
decoration: _inputDecoration("Enter your OTP").copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
decoration: _inputDecoration(
|
||||
"Enter your OTP",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.email_outlined,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? 'Required OTP' : null,
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required OTP'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 10),
|
||||
_buildLabel("New Password"),
|
||||
TextFormField(
|
||||
controller: _newPasswordController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
obscureText: _obscureText,
|
||||
decoration:
|
||||
_inputDecoration("Enter your new password").copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.key,
|
||||
size: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
obscureText: _obscureText,
|
||||
decoration: _inputDecoration(
|
||||
"Enter your new password",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(Icons.key, size: 16),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||
_obscureText
|
||||
? Icons.visibility_off
|
||||
: Icons.visibility,
|
||||
color: Color(0xFF12B24B),
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () =>
|
||||
setState(() => _obscureText = !_obscureText),
|
||||
onPressed:
|
||||
() => setState(
|
||||
() => _obscureText = !_obscureText,
|
||||
),
|
||||
),
|
||||
validator: (value) => value == null || value.isEmpty
|
||||
),
|
||||
validator:
|
||||
(value) =>
|
||||
value == null || value.isEmpty
|
||||
? 'Required New Password'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 10),
|
||||
_buildLabel("Confirm Password"),
|
||||
TextFormField(
|
||||
controller: _confirmPasswordController,
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w600, fontSize: 11),
|
||||
obscureText: _obscureText,
|
||||
decoration:
|
||||
_inputDecoration("Enter your confirm password").copyWith(
|
||||
prefixIcon: Icon(
|
||||
Icons.key,
|
||||
size: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 11,
|
||||
),
|
||||
obscureText: _obscureText,
|
||||
decoration: _inputDecoration(
|
||||
"Enter your confirm password",
|
||||
).copyWith(
|
||||
prefixIcon: Icon(Icons.key, size: 16),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||
_obscureText
|
||||
? Icons.visibility_off
|
||||
: Icons.visibility,
|
||||
color: Color(0xFF12B24B),
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () =>
|
||||
setState(() => _obscureText = !_obscureText),
|
||||
onPressed:
|
||||
() => setState(
|
||||
() => _obscureText = !_obscureText,
|
||||
),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
@ -611,13 +744,14 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
if (!_formKey.currentState!.validate())
|
||||
return;
|
||||
setState(() {
|
||||
_isForgotPassword = false;
|
||||
_showOtpResetFields = true;
|
||||
@ -626,31 +760,39 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
_onSubmit(context);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF12B24B), // Button color
|
||||
foregroundColor: Colors.white, // Text color
|
||||
backgroundColor: Color(
|
||||
0xFF12B24B,
|
||||
), // Button color
|
||||
foregroundColor:
|
||||
Colors.white, // Text color
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 12),
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18)),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 10),
|
||||
horizontal: 24,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Submit",
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w800, fontSize: 15),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 13.5,
|
||||
),
|
||||
SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
SizedBox(width: 3),
|
||||
Icon(
|
||||
Icons.arrow_forward_sharp,
|
||||
color: Colors.white,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -659,7 +801,7 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
if (!_isForgotPassword && !_showOtpResetFields)
|
||||
Center(
|
||||
child: TextButton(
|
||||
@ -678,7 +820,8 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
|
||||
color: Color(0xFF212121), // Text color
|
||||
decoration:
|
||||
TextDecoration.underline, // Underline the text
|
||||
TextDecoration
|
||||
.underline, // Underline the text
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -701,13 +844,14 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
|
||||
color: Color(0xFF212121), // Text color
|
||||
decoration:
|
||||
TextDecoration.underline, // Underline the text
|
||||
TextDecoration
|
||||
.underline, // Underline the text
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
if (!_isForgotPassword && !_showOtpResetFields)
|
||||
Row(
|
||||
children: [
|
||||
@ -717,10 +861,14 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
handleMS();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white, // Button color
|
||||
foregroundColor: Colors.black, // Text color
|
||||
backgroundColor:
|
||||
Colors.white, // Button color
|
||||
foregroundColor:
|
||||
Colors.black, // Text color
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 5),
|
||||
horizontal: 24,
|
||||
vertical: 5,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
side: BorderSide(
|
||||
@ -731,18 +879,20 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 5),
|
||||
horizontal: 24,
|
||||
vertical: 3,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Sign In With Microsoft",
|
||||
style: GoogleFonts.poppins(
|
||||
fontWeight: FontWeight.w500, fontSize: 14),
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
SizedBox(width: 3),
|
||||
Image.asset(
|
||||
'assets/images/login/microsoft.png',
|
||||
width: 30, // Optional: control size
|
||||
@ -783,6 +933,13 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -797,7 +954,8 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF212121)),
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -826,8 +984,10 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
final url = '$apiUrl/auth/mslogin';
|
||||
print(url);
|
||||
try {
|
||||
final response = await http
|
||||
.get(Uri.parse(url), headers: {'Content-Type': 'application/json'});
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
print("inside try method");
|
||||
if (response.statusCode == 200) {
|
||||
final authUrl = json.decode(response.body)['auth_url'];
|
||||
|
||||
@ -24,14 +24,15 @@ class ForexScreen extends StatefulWidget {
|
||||
final Function(Map<String, dynamic>) onSaveForex;
|
||||
final String? loginUser;
|
||||
|
||||
ForexScreen(
|
||||
{required this.onClose,
|
||||
ForexScreen({
|
||||
required this.onClose,
|
||||
this.apiData,
|
||||
required this.selectedItem,
|
||||
required this.apiCountryData,
|
||||
required this.onSaveForex,
|
||||
required this.loginUser,
|
||||
required this.flightData});
|
||||
required this.flightData,
|
||||
});
|
||||
|
||||
@override
|
||||
_ForexScreenState createState() => _ForexScreenState();
|
||||
@ -75,16 +76,18 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
"_cash",
|
||||
"_checkForex",
|
||||
"_deliveryLocation",
|
||||
"_comments"
|
||||
"_comments",
|
||||
];
|
||||
|
||||
String _formatDate(String? date) {
|
||||
if (date == null || date.isEmpty) return "";
|
||||
try {
|
||||
DateTime parsedDate =
|
||||
DateTime.parse(date); // Assuming input is YYYY-MM-DD
|
||||
return DateFormat("dd-MM-yyyy")
|
||||
.format(parsedDate); // Convert to DD-MM-YYYY
|
||||
DateTime parsedDate = DateTime.parse(
|
||||
date,
|
||||
); // Assuming input is YYYY-MM-DD
|
||||
return DateFormat(
|
||||
"dd-MM-yyyy",
|
||||
).format(parsedDate); // Convert to DD-MM-YYYY
|
||||
} catch (e) {
|
||||
print("Error formatting date: $e");
|
||||
return date; // Return as is if parsing fails
|
||||
@ -146,7 +149,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
"country_code": selectedCountry,
|
||||
"start_date": _formatDate(textControllers["_forexStartDate"]?.text),
|
||||
"end_date": _formatDate(textControllers["_forexEndDate"]?.text),
|
||||
"user_id": tripuserId
|
||||
"user_id": tripuserId,
|
||||
// "currency": selectedCurrency ?? "",
|
||||
};
|
||||
}
|
||||
@ -195,10 +198,12 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
selectedDuration = responseData["duration"]?.toString() ?? "";
|
||||
selectedQuotedAmount =
|
||||
responseData["perdiem_amount"]?.toString() ?? "";
|
||||
selectedCardPercent =
|
||||
int.tryParse(responseData["card_percentage"]?.toString() ?? "");
|
||||
selectedCashPercent =
|
||||
int.tryParse(responseData["cash_percentage"]?.toString() ?? "");
|
||||
selectedCardPercent = int.tryParse(
|
||||
responseData["card_percentage"]?.toString() ?? "",
|
||||
);
|
||||
selectedCashPercent = int.tryParse(
|
||||
responseData["cash_percentage"]?.toString() ?? "",
|
||||
);
|
||||
|
||||
textControllers["_cardNumber"]?.text =
|
||||
responseData["forex_card_no"]?.toString() ?? "";
|
||||
@ -249,17 +254,16 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
}
|
||||
|
||||
Map<String, String?> getFlightTripDateRange(
|
||||
List<Map<String, dynamic>> flightData) {
|
||||
final allTrips = flightData
|
||||
List<Map<String, dynamic>> flightData,
|
||||
) {
|
||||
final allTrips =
|
||||
flightData
|
||||
.expand((flight) => flight['trips'] ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.toList();
|
||||
|
||||
if (allTrips.isEmpty) {
|
||||
return {
|
||||
'firstTripDate': null,
|
||||
'lastTripDate': null,
|
||||
};
|
||||
return {'firstTripDate': null, 'lastTripDate': null};
|
||||
}
|
||||
|
||||
allTrips.sort((a, b) {
|
||||
@ -352,18 +356,22 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// ✅ Only set controller after value is updated
|
||||
// final parsedDate =
|
||||
// DateTime.tryParse(flightFirstTripDateNotifier.value ?? '');
|
||||
final parsedDate = DateFormat("dd-MM-yyyy")
|
||||
.parse(flightFirstTripDateNotifier.value ?? '');
|
||||
final parsedDate = DateFormat(
|
||||
"dd-MM-yyyy",
|
||||
).parse(flightFirstTripDateNotifier.value ?? '');
|
||||
if (parsedDate != null) {
|
||||
textControllers["_forexStartDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(parsedDate);
|
||||
textControllers["_forexStartDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(parsedDate);
|
||||
}
|
||||
|
||||
final parsedEndDate = DateFormat("dd-MM-yyyy")
|
||||
.parse(flightLastTripDateNotifier.value ?? '');
|
||||
final parsedEndDate = DateFormat(
|
||||
"dd-MM-yyyy",
|
||||
).parse(flightLastTripDateNotifier.value ?? '');
|
||||
if (parsedEndDate != null) {
|
||||
textControllers["_forexEndDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(parsedEndDate);
|
||||
textControllers["_forexEndDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(parsedEndDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -392,8 +400,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
textControllers["_cardNumber"] = initController("card_number");
|
||||
textControllers["_card"] = initController("deposit_on_card");
|
||||
textControllers["_cash"] = initController("deposit_on_cash");
|
||||
textControllers["_deliveryLocation"] =
|
||||
initController("delivery_location");
|
||||
textControllers["_deliveryLocation"] = initController(
|
||||
"delivery_location",
|
||||
);
|
||||
textControllers["_comments"] = initController("comments");
|
||||
|
||||
// Set dropdown values
|
||||
@ -401,9 +410,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
selectedCurrency = widget.selectedItem!["currency"] as String?;
|
||||
selectedDuration = widget.selectedItem!["duration"] as String?;
|
||||
selectedCardPercent = int.tryParse(
|
||||
widget.selectedItem!["card_percentage"]?.toString() ?? "");
|
||||
widget.selectedItem!["card_percentage"]?.toString() ?? "",
|
||||
);
|
||||
selectedCashPercent = int.tryParse(
|
||||
widget.selectedItem!["cash_percentage"]?.toString() ?? "");
|
||||
widget.selectedItem!["cash_percentage"]?.toString() ?? "",
|
||||
);
|
||||
selectedPerdiemAmount = widget.selectedItem!["perdiem_amount"] as String?;
|
||||
isChecked =
|
||||
widget.selectedItem!["have_card"] == "1"; // Convert string to bool
|
||||
@ -473,7 +484,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
if (startDateString == null || endDateString == null) return;
|
||||
print(
|
||||
"Calculate 3 - StarrtDAte: $startDateString --EndDate: $endDateString");
|
||||
"Calculate 3 - StarrtDAte: $startDateString --EndDate: $endDateString",
|
||||
);
|
||||
|
||||
try {
|
||||
// Parse the dates from string
|
||||
@ -548,7 +560,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
if (quotedAmount != null) {
|
||||
// fifteenPercent = (quotedAmount * 15) ~/ 100;
|
||||
print("selectedCardPercent - $selectedCashPercent");
|
||||
fifteenPercent = (quotedAmount * selectedCashPercent!) ~/
|
||||
fifteenPercent =
|
||||
(quotedAmount * selectedCashPercent!) ~/
|
||||
100; // Calculate 15% (integer division)
|
||||
remainingAmount = quotedAmount - fifteenPercent; // Subtract from total
|
||||
|
||||
@ -587,10 +600,12 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
int checkValidAmount = cashAmount + enteredAmount;
|
||||
|
||||
print(
|
||||
"checkValidAmount - $checkValidAmount - $enteredAmount - $cashAmount");
|
||||
"checkValidAmount - $checkValidAmount - $enteredAmount - $cashAmount",
|
||||
);
|
||||
|
||||
print(
|
||||
"CAsh - $cashAmount- CaRd- $enteredAmount - $calculateAmnt - selectedQuotedAmount - $qouteAmount");
|
||||
"CAsh - $cashAmount- CaRd- $enteredAmount - $calculateAmnt - selectedQuotedAmount - $qouteAmount",
|
||||
);
|
||||
|
||||
if (enteredAmount == null || calculateAmnt > qouteAmount!) {
|
||||
errorMessages["deposit_on_card"] = "Amount cannot exceed $qouteAmount";
|
||||
@ -619,19 +634,20 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
int checkValidAmount = cardAmount! + enteredAmount;
|
||||
|
||||
print(
|
||||
"checkValidAmountCash - $checkValidAmount -cash- $enteredAmount -Card - $cardAmount - quotedAmount- $quotedAmount");
|
||||
"checkValidAmountCash - $checkValidAmount -cash- $enteredAmount -Card - $cardAmount - quotedAmount- $quotedAmount",
|
||||
);
|
||||
|
||||
print("Difference - $difference");
|
||||
print('CardAmount - $cardAmount');
|
||||
textControllers["_card"]?.text = difference.toString();
|
||||
|
||||
// if (enteredAmount > fifteenPercent) {
|
||||
// errorMessages["deposit_on_cash"] = "Amount cannot exceed $fifteenPercent";
|
||||
// } else if (checkValidAmount == quotedAmount) {
|
||||
// errorMessages["deposit_on_card"] = " "; // Clear error if valid
|
||||
// } else {
|
||||
// errorMessages["deposit_on_cash"] = ""; // Clear error if valid
|
||||
// }
|
||||
if (enteredAmount > fifteenPercent) {
|
||||
errorMessages["deposit_on_cash"] = "Amount cannot exceed $fifteenPercent";
|
||||
} else if (checkValidAmount == quotedAmount) {
|
||||
errorMessages["deposit_on_card"] = " "; // Clear error if valid
|
||||
} else {
|
||||
errorMessages["deposit_on_cash"] = ""; // Clear error if valid
|
||||
}
|
||||
|
||||
// Refresh UI if using StatefulWidget
|
||||
setState(() {});
|
||||
@ -653,10 +669,12 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
void _validateDates() {
|
||||
print("VALiDATING DATES");
|
||||
|
||||
DateTime? startDate =
|
||||
_parseDate(textControllers["_forexStartDate"]?.text ?? "");
|
||||
DateTime? endDate =
|
||||
_parseDate(textControllers["_forexEndDate"]?.text ?? "");
|
||||
DateTime? startDate = _parseDate(
|
||||
textControllers["_forexStartDate"]?.text ?? "",
|
||||
);
|
||||
DateTime? endDate = _parseDate(
|
||||
textControllers["_forexEndDate"]?.text ?? "",
|
||||
);
|
||||
|
||||
if (startDate != null && endDate != null && endDate.isBefore(startDate)) {
|
||||
setState(() {
|
||||
@ -672,9 +690,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isMobile = sizingInfo.isMobile;
|
||||
bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Container(
|
||||
// color: Color(0xFFF4F4FB),
|
||||
@ -689,13 +709,14 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
child: Center(
|
||||
child: Column(children: _buildAccomadtionForm(isDesktop)),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildAccomadtionForm(bool isDesktop) {
|
||||
@ -714,9 +735,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
return [
|
||||
...buildResponsiveRow(_buildFirstRow(isDesktop)),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
// Align(
|
||||
// alignment: Alignment.centerLeft,
|
||||
// child: Text(
|
||||
@ -743,9 +762,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// Divider(
|
||||
// thickness: 0.3,
|
||||
// ),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
...buildResponsiveRow(_buildSecondRow(isDesktop)),
|
||||
...buildResponsiveRow(_buildCardDetailsRow(isDesktop)),
|
||||
...buildResponsiveRow(_buildForexCard(isDesktop)),
|
||||
@ -769,8 +786,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
initialDate = DateTime.parse(flightFirstTripDateNotifier.value!);
|
||||
// textControllers["_forexStartDate"]?.text =
|
||||
// DateFormat('yyyy-MM-dd').format(initialDate);
|
||||
textControllers["_forexStartDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(initialDate);
|
||||
textControllers["_forexStartDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(initialDate);
|
||||
} catch (e) {
|
||||
initialDate = today;
|
||||
}
|
||||
@ -804,8 +822,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
|
||||
setState(() {
|
||||
_selectedCheckOutDate = pickedDate;
|
||||
textControllers["_forexStartDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(pickedDate);
|
||||
textControllers["_forexStartDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(pickedDate);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -854,8 +873,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
if (pickedDate != null && pickedDate != _selectedEndDate) {
|
||||
setState(() {
|
||||
_selectedEndDate = pickedDate;
|
||||
textControllers["_forexEndDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(pickedDate);
|
||||
textControllers["_forexEndDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(pickedDate);
|
||||
// textControllers["_forexEndDate"]?.text =
|
||||
// DateFormat('dd-MM-yyyy').format(initialDate);
|
||||
});
|
||||
@ -871,7 +891,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -888,10 +909,12 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
await _selectCheckOutDate(context);
|
||||
|
||||
if (textControllers["_forexEndDate"]!.text.isNotEmpty) {
|
||||
DateTime? startDate =
|
||||
_parseDate(textControllers["_forexStartDate"]!.text);
|
||||
DateTime? endDate =
|
||||
_parseDate(textControllers["_forexEndDate"]!.text);
|
||||
DateTime? startDate = _parseDate(
|
||||
textControllers["_forexStartDate"]!.text,
|
||||
);
|
||||
DateTime? endDate = _parseDate(
|
||||
textControllers["_forexEndDate"]!.text,
|
||||
);
|
||||
|
||||
if (startDate != null &&
|
||||
endDate != null &&
|
||||
@ -914,13 +937,18 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Select Date",
|
||||
labelStyle:
|
||||
const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
labelStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 16),
|
||||
suffixIcon: const Icon(Icons.calendar_today,
|
||||
size: 16, color: Colors.grey),
|
||||
suffixIcon: const Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -936,12 +964,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
Spacer()
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) Spacer() else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -950,7 +973,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -964,10 +988,12 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
await _selectForexEndDate(context);
|
||||
|
||||
if (textControllers["_forexEndDate"]!.text.isNotEmpty) {
|
||||
DateTime? startDate =
|
||||
_parseDate(textControllers["_forexStartDate"]!.text);
|
||||
DateTime? endDate =
|
||||
_parseDate(textControllers["_forexEndDate"]!.text);
|
||||
DateTime? startDate = _parseDate(
|
||||
textControllers["_forexStartDate"]!.text,
|
||||
);
|
||||
DateTime? endDate = _parseDate(
|
||||
textControllers["_forexEndDate"]!.text,
|
||||
);
|
||||
|
||||
if (startDate != null &&
|
||||
endDate != null &&
|
||||
@ -995,8 +1021,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
suffixIcon: Icon(Icons.calendar_today,
|
||||
size: 16, color: Colors.grey),
|
||||
suffixIcon: Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1013,12 +1042,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
Spacer()
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) Spacer() else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -1027,7 +1051,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1045,7 +1070,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
// decoration: const InputDecoration(
|
||||
// labelText: "To",
|
||||
// labelStyle: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
@ -1071,7 +1097,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// Map country codes to country names
|
||||
countryMap = {
|
||||
for (var item in countryList)
|
||||
item['country_code'] as String: item['country_name'] as String
|
||||
item['country_code'] as String: item['country_name'] as String,
|
||||
};
|
||||
|
||||
// Extract only country codes for processing
|
||||
@ -1101,7 +1127,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1124,12 +1151,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
dropdownSearchDecoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 1,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@ -1140,7 +1166,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
// Find the country_code based on selected country_name
|
||||
selectedCountry = countryMap.entries
|
||||
selectedCountry =
|
||||
countryMap.entries
|
||||
.firstWhere((entry) => entry.value == newValue)
|
||||
.key;
|
||||
_onCountryChanged(selectedCountry);
|
||||
@ -1164,13 +1191,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// height: 8,
|
||||
// ),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.048,
|
||||
)
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.048)
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
@ -1179,7 +1202,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1202,7 +1226,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1211,12 +1236,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
),
|
||||
// if (isDesktop)SizedBox(width: 8,) else SizedBox(height: 8,),
|
||||
if (isDesktop)
|
||||
Spacer()
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) Spacer() else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -1225,7 +1245,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1243,7 +1264,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
// decoration: const InputDecoration(
|
||||
// labelText: "To",
|
||||
// labelStyle: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
@ -1279,7 +1301,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Container(
|
||||
@ -1298,8 +1321,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
},
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(
|
||||
r'^\d*\.?\d*$')), // Allow only positive numbers with optional decimal
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d*\.?\d*$'),
|
||||
), // Allow only positive numbers with optional decimal
|
||||
],
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
@ -1310,7 +1334,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
// CustomTextFieldItnerarySubWrapper(
|
||||
// width: isDesktop ? MediaQuery.of(context).size.width * 0.07 : null,
|
||||
// isFocused: focusStates["_transport"] ?? false,
|
||||
@ -1339,14 +1363,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// ),
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: 10,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) SizedBox(width: 10) else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -1355,7 +1372,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Container(
|
||||
@ -1374,8 +1392,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
},
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(
|
||||
r'^\d*\.?\d*$')), // Allow only positive numbers with optional decimal
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d*\.?\d*$'),
|
||||
), // Allow only positive numbers with optional decimal
|
||||
],
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
@ -1386,7 +1405,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
// CustomTextFieldItnerarySubWrapper(
|
||||
// width: isDesktop ? MediaQuery.of(context).size.width * 0.07 : null,
|
||||
// isFocused: focusStates["_accomodation"] ?? false,
|
||||
@ -1415,14 +1434,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// ),
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: 10,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) SizedBox(width: 10) else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -1431,14 +1443,14 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Container(
|
||||
color: Colors.yellow.shade50,
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
width:
|
||||
isDesktop ? MediaQuery.of(context).size.width * 0.06 : null,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.06 : null,
|
||||
height: 30,
|
||||
child: TextField(
|
||||
focusNode: focusNodes["_telephone"],
|
||||
@ -1451,8 +1463,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
},
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(
|
||||
r'^\d*\.?\d*$')), // Allow only positive numbers with optional decimal
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d*\.?\d*$'),
|
||||
), // Allow only positive numbers with optional decimal
|
||||
],
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
@ -1462,7 +1475,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
))
|
||||
),
|
||||
),
|
||||
// CustomTextFieldItnerarySubWrapper(
|
||||
// width: isDesktop ? MediaQuery.of(context).size.width * 0.07 : null,
|
||||
// isFocused: focusStates["_telephone"] ?? false,
|
||||
@ -1491,14 +1505,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// ),
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: 40,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) SizedBox(width: 40) else SizedBox(height: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -1507,7 +1514,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1525,7 +1533,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
// decoration: const InputDecoration(
|
||||
// labelText: "To",
|
||||
// labelStyle: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
@ -1545,19 +1554,24 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
List<Widget> _buildCardDetailsRow(bool isDesktop) {
|
||||
List<dynamic> purposeList = widget.apiData?['flight_class'] ?? [];
|
||||
|
||||
List<DropdownMenuItem<String>> dropdownItems = purposeList
|
||||
.map((item) => DropdownMenuItem<String>(
|
||||
List<DropdownMenuItem<String>> dropdownItems =
|
||||
purposeList
|
||||
.map(
|
||||
(item) => DropdownMenuItem<String>(
|
||||
value: item['dropdown_value'],
|
||||
child: Text(item['dropdown_value']),
|
||||
))
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
if (dropdownItems.isEmpty) {
|
||||
dropdownItems.add(
|
||||
DropdownMenuItem<String>(
|
||||
value: null,
|
||||
child: Text("No options available",
|
||||
style: TextStyle(color: Colors.grey)),
|
||||
child: Text(
|
||||
"No options available",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1574,7 +1588,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1590,7 +1605,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
onChanged: (value) {
|
||||
// errorMessages["deposit_on_cash"] = "";
|
||||
_validateCashAmount(
|
||||
value); // Call validation when text changes
|
||||
value,
|
||||
); // Call validation when text changes
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Cash",
|
||||
@ -1613,12 +1629,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
),
|
||||
|
||||
if (isDesktop)
|
||||
Spacer()
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) Spacer() else SizedBox(height: 8),
|
||||
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -1628,7 +1639,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1643,7 +1655,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
_validateCardAmount(
|
||||
value); // Call validation when text changes
|
||||
value,
|
||||
); // Call validation when text changes
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Card",
|
||||
@ -1665,12 +1678,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
),
|
||||
|
||||
if (isDesktop)
|
||||
Spacer()
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (isDesktop) Spacer() else SizedBox(height: 8),
|
||||
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -1680,7 +1688,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1698,7 +1707,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1826,7 +1836,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldWrapper(
|
||||
@ -1853,9 +1864,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
),
|
||||
if (isDesktop) Spacer(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
// Actions row remains a Row
|
||||
Column(
|
||||
children: [
|
||||
@ -1879,7 +1888,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldForexWrapper(
|
||||
@ -1919,16 +1929,17 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldWrapper(
|
||||
isFocused: focusStates["_deliveryLocation"] ??
|
||||
isFocused:
|
||||
focusStates["_deliveryLocation"] ??
|
||||
false, // Dropdown doesn't use focus
|
||||
isDesktop: isDesktop,
|
||||
width: isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.45
|
||||
: null,
|
||||
width:
|
||||
isDesktop ? MediaQuery.of(context).size.width * 0.45 : null,
|
||||
child: SizedBox(
|
||||
height: 35,
|
||||
child: TextField(
|
||||
@ -1955,13 +1966,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.04,
|
||||
)
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.04)
|
||||
else
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
@ -1997,7 +2004,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74)),
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -2015,9 +2023,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.grey[400], // Light grey color
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
child: Text(
|
||||
@ -2026,7 +2032,6 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10), // Space between buttons
|
||||
|
||||
// Save Changes Button
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
@ -2034,9 +2039,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF114D8B), // Primary color for save
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
child: Text(
|
||||
|
||||
@ -42,7 +42,7 @@ class _PlaceholdersModalState extends State<PlaceholdersModal> {
|
||||
content: Container(
|
||||
width:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.3
|
||||
? MediaQuery.of(context).size.width * 0.4
|
||||
: double.maxFinite,
|
||||
// Set max height so ListView knows constraints
|
||||
height: 300,
|
||||
|
||||
@ -642,7 +642,7 @@ class TemplateState extends State<Template> {
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
height: 200,
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Color(0xFFD6D5E6), width: 0.5),
|
||||
|
||||
830
lib/Screens/myTemplates/templateForex.dart
Normal file
830
lib/Screens/myTemplates/templateForex.dart
Normal file
@ -0,0 +1,830 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io show Directory, File;
|
||||
import 'package:delta_to_html/delta_to_html.dart';
|
||||
import 'package:flutter/cupertino.dart' as dom;
|
||||
import 'package:flutter_quill/flutter_quill.dart' hide Text;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_quill/flutter_quill.dart' hide Text;
|
||||
import 'package:flutter_quill/quill_delta.dart';
|
||||
import 'package:flutter_quill/quill_delta.dart' as quill;
|
||||
import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart';
|
||||
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
|
||||
import 'package:frontend/Screens/myTemplates/templateForex.dart'
|
||||
as _editorFocusNode;
|
||||
import 'package:frontend/Screens/myTemplates/templateForex.dart'
|
||||
as _editorScrollController;
|
||||
import 'package:frontend/Screens/myTemplates/templateForex.dart' as _controller;
|
||||
import 'package:html2md/html2md.dart' as html2md;
|
||||
import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart';
|
||||
|
||||
import 'package:flutter_quill/flutter_quill.dart' as quill;
|
||||
import 'package:html/parser.dart' show parse;
|
||||
import 'package:html/dom.dart' as dom hide Element, Text;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_quill/flutter_quill.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_quill/flutter_quill_internal.dart';
|
||||
import 'package:flutter_quill/quill_delta.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
|
||||
import '../../config/apiUrl.dart';
|
||||
import '../../routes/custom_appBar.dart';
|
||||
import '../../routes/custom_drawer.dart';
|
||||
import '../../services/apiService.dart';
|
||||
import '../../utils/auth_utils.dart';
|
||||
import '../../widgets/custom_user_travel.dart';
|
||||
import 'dialog_placeholders.dart';
|
||||
|
||||
class TemplateForex extends StatefulWidget {
|
||||
final Map<String, dynamic>? templateData;
|
||||
|
||||
const TemplateForex({super.key, required this.templateData});
|
||||
|
||||
static TemplateForex fromState(GoRouterState state) {
|
||||
return TemplateForex(templateData: state.extra as Map<String, dynamic>?);
|
||||
}
|
||||
|
||||
@override
|
||||
TemplateForexState createState() => TemplateForexState();
|
||||
}
|
||||
|
||||
class TemplateForexState extends State<TemplateForex> {
|
||||
final ApiService apiService = ApiService();
|
||||
|
||||
// final QuillController _controller = QuillController.basic();
|
||||
String? orgId;
|
||||
String? userId;
|
||||
Color layoutColor = Colors.redAccent;
|
||||
Color bodyColor = Colors.white;
|
||||
final Map<String, TextEditingController> controllers = {};
|
||||
List<String> dataHeader = ["subject"];
|
||||
List<String> placeholders = [];
|
||||
|
||||
late QuillController _controller = QuillController.basic();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
late int templateId = 0;
|
||||
late String templateName = "";
|
||||
late List<Map<String, dynamic>> placeholderList = [];
|
||||
|
||||
Map<String, dynamic> get TemplateData {
|
||||
final data = {
|
||||
"org_id": orgId,
|
||||
|
||||
// "template_id": templateId,
|
||||
// "template_name": controllers["templateName"]?.text,
|
||||
"template_id": templateId,
|
||||
"template_name": templateName,
|
||||
"subject": controllers["subject"]?.text,
|
||||
"body_html": DeltaToHTML.encodeJson(
|
||||
_controller.document.toDelta().toJson(),
|
||||
),
|
||||
// "body_html": jsonEncode(_controller.document.toDelta().toJson()),
|
||||
|
||||
// "body_html": _controller,
|
||||
// "body_html": convertQuillDocToHtml(_controller.document),
|
||||
// ✅ convert delta to HTML
|
||||
"placeholder": jsonEncode(placeholderList),
|
||||
// "created_by": userId
|
||||
};
|
||||
print('start 123');
|
||||
print(jsonEncode(_controller.document.toDelta().toJson()));
|
||||
// print(jsonEncode(_controller.document));
|
||||
// Only add group_id if it's an edit operation
|
||||
// if (widget.templateData != null && widget.templateData!.containsKey('group_id')) {
|
||||
// data["template_id"] = templateData;
|
||||
// }
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
@override
|
||||
// void dispose() {
|
||||
// // controllers.dispose();
|
||||
// // _editorScrollController.dispose();
|
||||
// _editorFocusNode.dispose();
|
||||
// super.dispose();
|
||||
// }
|
||||
void loadinitializeData() async {
|
||||
orgId = await getOrgId();
|
||||
userId = await getUserId();
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
|
||||
setState(() {
|
||||
layoutColor =
|
||||
layoutString != null
|
||||
? Color(int.parse(layoutString))
|
||||
: Colors.redAccent;
|
||||
|
||||
bodyColor =
|
||||
bodyStringColor != null
|
||||
? Color(int.parse(bodyStringColor))
|
||||
: Colors.white;
|
||||
});
|
||||
}
|
||||
|
||||
String convertQuillDocToHtml(quill.Document doc) {
|
||||
final buffer = StringBuffer();
|
||||
|
||||
print("convertQuillDocToHtml");
|
||||
for (final op in doc.toDelta().toList()) {
|
||||
final insert = op.data;
|
||||
final attrs = op.attributes ?? {};
|
||||
|
||||
if (insert is String) {
|
||||
var content = insert;
|
||||
|
||||
// Handle formatting (bold, italic, etc.)
|
||||
if (attrs.containsKey('bold')) {
|
||||
content = '<strong>$content</strong>';
|
||||
}
|
||||
if (attrs.containsKey('italic')) {
|
||||
content = '<em>$content</em>';
|
||||
}
|
||||
|
||||
// Wrap each paragraph with <p>
|
||||
if (content.trim().isNotEmpty) {
|
||||
buffer.write('<p>${content.trim()}</p>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String convertQuillDocToHtml2(quill.Document doc) {
|
||||
final buffer = StringBuffer();
|
||||
final lines = <String>[];
|
||||
final delta = doc.toDelta();
|
||||
|
||||
String applyStyles(String text, Map<String, dynamic>? attrs) {
|
||||
if (attrs == null) return text;
|
||||
if (attrs.containsKey('bold')) {
|
||||
text = '<strong>$text</strong>';
|
||||
}
|
||||
if (attrs.containsKey('italic')) {
|
||||
text = '<em>$text</em>';
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
for (final op in delta.toList()) {
|
||||
final insert = op.data;
|
||||
final attrs = op.attributes;
|
||||
|
||||
if (insert is String) {
|
||||
final parts = insert.split('\n');
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
final part = applyStyles(parts[i], attrs);
|
||||
lines.add(part);
|
||||
|
||||
if (i < parts.length - 1) {
|
||||
// End of line: wrap accumulated content into <p>
|
||||
final joined = lines.join('');
|
||||
if (joined.trim().isNotEmpty) {
|
||||
buffer.writeln('<p>${joined.trim()}</p>');
|
||||
}
|
||||
lines.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add remaining lines
|
||||
final joined = lines.join('');
|
||||
if (joined.trim().isNotEmpty) {
|
||||
buffer.writeln('<p>${joined.trim()}</p>');
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String extractPlainTextFromHtml(String html) {
|
||||
final regex = RegExp(r'<p>(.*?)<\/p>', multiLine: true, dotAll: true);
|
||||
final matches = regex.allMatches(html);
|
||||
|
||||
final buffer = StringBuffer();
|
||||
for (final match in matches) {
|
||||
final text = match.group(1)?.replaceAll(RegExp(r'<[^>]*>'), '') ?? '';
|
||||
buffer.writeln(text.trim());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String decodeHtmlEntities(String text) {
|
||||
return text
|
||||
.replaceAll(' ', ' ')
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll(''', "'"); // add more as needed
|
||||
}
|
||||
|
||||
// quill.Document convertSimpleHtmlToQuill(String htmlString) {
|
||||
// final delta = quill.Delta();
|
||||
// final doc = html_parser.parse(htmlString);
|
||||
// final body = doc.body;
|
||||
//
|
||||
// void walk(Node node) {
|
||||
// if (node is Text) {
|
||||
// delta.insert(node.text);
|
||||
// } else if (node is Element) {
|
||||
// switch (node.localName) {
|
||||
// case 'p':
|
||||
// node.nodes.forEach(walk);
|
||||
// delta.insert('\n');
|
||||
// break;
|
||||
// case 'br':
|
||||
// delta.insert('\n');
|
||||
// break;
|
||||
// case 'strong':
|
||||
// case 'b':
|
||||
// delta.insert(node.text, {'bold': true});
|
||||
// break;
|
||||
// case 'em':
|
||||
// case 'i':
|
||||
// delta.insert(node.text, {'italic': true});
|
||||
// break;
|
||||
// case 'a':
|
||||
// delta.insert(node.text, {'link': node.attributes['href']});
|
||||
// break;
|
||||
// default:
|
||||
// node.nodes.forEach(walk);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (body != null) {
|
||||
// walk(body);
|
||||
// }
|
||||
//
|
||||
// return quill.Document.fromDelta(delta..insert('\n'));
|
||||
// }
|
||||
|
||||
String formatTemplateName(String input) {
|
||||
return input
|
||||
.split('_') // split by underscore
|
||||
.map(
|
||||
(word) =>
|
||||
word.isNotEmpty
|
||||
? '${word[0].toUpperCase()}${word.substring(1)}'
|
||||
: '',
|
||||
)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
Future<void> updateData() async {
|
||||
// Ensure apiselectedUser is not null before printing
|
||||
if (widget.templateData != null) {
|
||||
print("API Selected User Has Data - ${widget.templateData}");
|
||||
print(
|
||||
"API Selected User Has - ${widget.templateData?["templateData"]?["subject"]}",
|
||||
);
|
||||
setState(() {
|
||||
// ✅ Wrap in setState to update the UI
|
||||
controllers["templateName"]?.text =
|
||||
widget.templateData?["templateData"]?["template_name"] ?? "";
|
||||
|
||||
controllers["subject"]?.text =
|
||||
widget.templateData?["templateData"]?["subject"] ?? "";
|
||||
final bodyHtml =
|
||||
widget.templateData?["templateData"]?["body_html"] ?? "";
|
||||
|
||||
print("bodyHtml - $bodyHtml");
|
||||
|
||||
String html = widget.templateData?["templateData"]?["body_html"] ?? "";
|
||||
|
||||
final htmlToDelta = HtmlToDelta();
|
||||
|
||||
// Convert the HTML string to Quill Delta format
|
||||
// This is where the magic happens, but also where complex HTML might be simplified
|
||||
final quill.Delta initialDelta = htmlToDelta.convert(html);
|
||||
|
||||
// Create a Quill Document from the Delta
|
||||
final quill.Document quillDoc = quill.Document.fromDelta(initialDelta);
|
||||
|
||||
// Initialize the QuillController with the converted document
|
||||
_controller = quill.QuillController(
|
||||
document: quillDoc,
|
||||
selection: const TextSelection.collapsed(
|
||||
offset: 0,
|
||||
), // Cursor at the start
|
||||
);
|
||||
|
||||
// final plainText = extractPlainTextFromHtml(bodyHtml);
|
||||
// final decodedText = decodeHtmlEntities(plainText);
|
||||
// final quillDoc = quill.Document()..insert(0, decodedText);
|
||||
// _controller = quill.QuillController(
|
||||
// document: quillDoc,
|
||||
// selection: const TextSelection.collapsed(offset: 0),
|
||||
// );
|
||||
|
||||
templateName =
|
||||
widget.templateData?["templateData"]?["template_name"] ?? "";
|
||||
|
||||
print("Fetched template_name: $templateName");
|
||||
|
||||
final rawPlaceholder =
|
||||
widget.templateData?["templateData"]?["placeholder"];
|
||||
|
||||
if (rawPlaceholder is String) {
|
||||
// If it's a JSON string, decode it first
|
||||
placeholderList = List<Map<String, dynamic>>.from(
|
||||
jsonDecode(rawPlaceholder),
|
||||
);
|
||||
} else if (rawPlaceholder is List) {
|
||||
// If it's already a list (ideal case)
|
||||
placeholderList = List<Map<String, dynamic>>.from(rawPlaceholder);
|
||||
}
|
||||
|
||||
print("Extracted placeholders: $placeholders");
|
||||
|
||||
print("Fetched placeholders: $placeholderList");
|
||||
|
||||
templateId =
|
||||
int.tryParse(
|
||||
widget.templateData?["templateData"]?["template_id"]
|
||||
?.toString() ??
|
||||
'0',
|
||||
) ??
|
||||
0;
|
||||
print("Fetched template_id: $templateId");
|
||||
|
||||
// if (widget.group?["international_policy_id"] != null) {
|
||||
// selectedInternational =
|
||||
// widget.group!["international_policy_id"].toString();
|
||||
// }
|
||||
});
|
||||
} else {
|
||||
print("API Selected User Has Data - No data available yet");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleSubmit() async {
|
||||
Map<String, dynamic> data = TemplateData;
|
||||
|
||||
print('TemplateData - $data');
|
||||
// final String deltaJsonString = TemplateData?["body_html"] ?? "[]";
|
||||
//
|
||||
// print('deltaJsonString $deltaJsonString');
|
||||
//
|
||||
// // Decode the JSON string into a list
|
||||
// final List<dynamic> deltaJson = jsonDecode(deltaJsonString);
|
||||
//
|
||||
// print(DeltaToHTML.encodeJson(deltaJson));
|
||||
//
|
||||
// // Then convert it to a Quill document
|
||||
// final doc = Document.fromJson(List<Map<String, dynamic>>.from(deltaJson));
|
||||
//
|
||||
// // Set it to the controller
|
||||
// _controller = QuillController(
|
||||
// document: doc,
|
||||
// selection: const TextSelection.collapsed(offset: 0),
|
||||
// );
|
||||
// print('doc JSON: ${jsonEncode(doc.toDelta().toJson())}');
|
||||
// print('doc plain text: ${doc.toPlainText()}');
|
||||
// print('doc $doc');
|
||||
|
||||
setState(() {
|
||||
updateTemplateData(data);
|
||||
// This triggers UI rebuild with error messages
|
||||
// if (validateData()) {
|
||||
// postGroupData();
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateTemplateData(policyData) async {
|
||||
final String apiUrldata = '$apiUrl/api/template/update/${templateId}';
|
||||
final token = await getToken(); // Fetch token
|
||||
|
||||
if (token == null) {
|
||||
throw Exception('Token not found. Please log in.');
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await http.put(
|
||||
Uri.parse(apiUrldata),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: jsonEncode(policyData), // Convert map to JSON
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print("policyData submitted successfully!");
|
||||
print("Response: ${response.body}");
|
||||
|
||||
context.go('/templateList');
|
||||
} else {
|
||||
print("Failed to submit policyData. Status: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
}
|
||||
} catch (e) {
|
||||
print(" Error submitting policyData: $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFf5f5f5),
|
||||
appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
drawer: CustomDrawer(isDesktop: false),
|
||||
body: Padding(
|
||||
padding:
|
||||
isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal:
|
||||
MediaQuery.of(context).size.width *
|
||||
0.1, // 30% of screen width as horizontal padding
|
||||
vertical:
|
||||
MediaQuery.of(context).size.height *
|
||||
0, // 5% of screen height as vertical padding
|
||||
)
|
||||
: EdgeInsets.all(0),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
Expanded(
|
||||
child: buildUserTable(
|
||||
isDesktop,
|
||||
context,
|
||||
bodyColor,
|
||||
layoutColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildUserTable(
|
||||
bool isDesktop,
|
||||
context,
|
||||
Color? bodyColor,
|
||||
Color layoutColor,
|
||||
) {
|
||||
return Container(
|
||||
margin: isDesktop ? const EdgeInsets.only(top: 5.0, bottom: 10.0) : null,
|
||||
padding: const EdgeInsets.all(28),
|
||||
decoration: BoxDecoration(
|
||||
color: isDesktop ? Colors.white : Color(0xFFFCFCFC),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
formatTemplateName(templateName),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
|
||||
// SizedBox(height: 10),
|
||||
// buildTempalteSubject(isDesktop),
|
||||
//
|
||||
// SizedBox(height: 10),
|
||||
buildTempalteBody(isDesktop),
|
||||
Spacer(),
|
||||
buildActions(isDesktop),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTempalteSubject(bool isDesktop) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Subject",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserTravellerWrapper(
|
||||
isFocused: false,
|
||||
color: Colors.white,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.8 : null,
|
||||
isDesktop: isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: TextField(
|
||||
style: GoogleFonts.poppins(fontSize: 12, color: Colors.black),
|
||||
controller: controllers["subject"],
|
||||
onChanged: (value) {
|
||||
// _clearError("local_id_num");
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: "Enter the subject",
|
||||
labelStyle: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTempalteBody(bool isDesktop) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Text(
|
||||
// "Content",
|
||||
// style: GoogleFonts.poppins(
|
||||
// fontSize: 12,
|
||||
// fontWeight: FontWeight.w600,
|
||||
// color: Color(0xFF575A74),
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
color: Color(0xFFFFFEF0),
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.8 : null,
|
||||
child: IconTheme(
|
||||
data: IconThemeData(size: 18), // Set icon size here
|
||||
child: QuillSimpleToolbar(
|
||||
controller: _controller,
|
||||
config: QuillSimpleToolbarConfig(
|
||||
embedButtons: FlutterQuillEmbeds.toolbarButtons(),
|
||||
showClipboardPaste: true,
|
||||
customButtons: [
|
||||
QuillToolbarCustomButtonOptions(
|
||||
icon: const Icon(Icons.add_alarm_rounded),
|
||||
onPressed: () {
|
||||
_controller.document.insert(
|
||||
_controller.selection.extentOffset,
|
||||
TimeStampEmbed(DateTime.now().toString()),
|
||||
);
|
||||
|
||||
_controller.updateSelection(
|
||||
TextSelection.collapsed(
|
||||
offset: _controller.selection.extentOffset + 1,
|
||||
),
|
||||
ChangeSource.local,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
buttonOptions: QuillSimpleToolbarButtonOptions(
|
||||
base: QuillToolbarBaseButtonOptions(
|
||||
afterButtonPressed: () {
|
||||
final isDesktop = {
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.macOS,
|
||||
}.contains(defaultTargetPlatform);
|
||||
// if (isDesktop) {
|
||||
// _editorFocusNode.requestFocus();
|
||||
// }
|
||||
},
|
||||
),
|
||||
linkStyle: QuillToolbarLinkStyleButtonOptions(
|
||||
validateLink: (link) {
|
||||
// Treats all links as valid. When launching the URL,
|
||||
// `https://` is prefixed if the link is incomplete (e.g., `google.com` → `https://google.com`)
|
||||
// however this happens only within the editor.
|
||||
return true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final selected = await showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) =>
|
||||
PlaceholdersModal(placeholders: placeholderList),
|
||||
);
|
||||
|
||||
if (selected != null) {
|
||||
print("User selected placeholder: $selected");
|
||||
// You can now insert into a controller or editor
|
||||
// Ensure the editor is focused
|
||||
FocusScope.of(context).requestFocus(_focusNode);
|
||||
|
||||
final selection = _controller.selection;
|
||||
final position = selection.baseOffset;
|
||||
|
||||
// if (position >= 0) {
|
||||
// final intPosition = position.toInt();
|
||||
//
|
||||
// _controller.document.insert(intPosition, selected);
|
||||
//
|
||||
// _controller.updateSelection(
|
||||
// TextSelection.collapsed(
|
||||
// offset: intPosition + selected.length,
|
||||
// ),
|
||||
// ChangeSource.local,
|
||||
// );
|
||||
// }
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.grey,
|
||||
// padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
child: Text(
|
||||
'Placeholders',
|
||||
style: GoogleFonts.poppins(fontSize: 13, color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
height: MediaQuery.of(context).size.height * 0.5,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Color(0xFFD6D5E6), width: 0.5),
|
||||
),
|
||||
child: QuillEditor(
|
||||
controller: _controller,
|
||||
scrollController: ScrollController(),
|
||||
|
||||
focusNode: _focusNode,
|
||||
config: QuillEditorConfig(
|
||||
placeholder: 'Start writing your notes...',
|
||||
padding: const EdgeInsets.all(16),
|
||||
embedBuilders: [
|
||||
...FlutterQuillEmbeds.editorBuilders(
|
||||
imageEmbedConfig: QuillEditorImageEmbedConfig(
|
||||
imageProviderBuilder: (context, imageUrl) {
|
||||
// https://pub.dev/packages/flutter_quill_extensions#-image-assets
|
||||
if (imageUrl.startsWith('assets/')) {
|
||||
return AssetImage(imageUrl);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
videoEmbedConfig: QuillEditorVideoEmbedConfig(
|
||||
customVideoBuilder: (videoUrl, readOnly) {
|
||||
// To load YouTube videos https://github.com/singerdmx/flutter-quill/releases/tag/v10.8.0
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
TimeStampEmbedBuilder(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildActions(bool isDesktop) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
SizedBox(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
context.go('/OrganizationSettings');
|
||||
// You can get text from commentController.text
|
||||
Navigator.of(context).pop(); // Close the modal
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
foregroundColor: layoutColor,
|
||||
// backgroundColor: widget.layoutColor,
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(color: layoutColor, width: 2),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
child: Text(
|
||||
'Cancel',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: layoutColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
SizedBox(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
handleSubmit();
|
||||
// You can get text from commentController.text
|
||||
// Navigator.of(context).pop(); // Close the modal
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: layoutColor,
|
||||
// backgroundColor: widget.layoutColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'Save',
|
||||
style: GoogleFonts.poppins(fontSize: 14, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_editorScrollController.dispose();
|
||||
_editorFocusNode.dispose();
|
||||
}
|
||||
|
||||
class TimeStampEmbed extends Embeddable {
|
||||
const TimeStampEmbed(String value) : super(timeStampType, value);
|
||||
|
||||
static const String timeStampType = 'timeStamp';
|
||||
|
||||
static TimeStampEmbed fromDocument(Document document) =>
|
||||
TimeStampEmbed(jsonEncode(document.toDelta().toJson()));
|
||||
|
||||
Document get document => Document.fromJson(jsonDecode(data));
|
||||
}
|
||||
|
||||
class TimeStampEmbedBuilder extends EmbedBuilder {
|
||||
@override
|
||||
String get key => 'timeStamp';
|
||||
|
||||
@override
|
||||
String toPlainText(Embed node) {
|
||||
return node.value.data;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, EmbedContext embedContext) {
|
||||
return Row(
|
||||
children: [
|
||||
const Icon(Icons.access_time_rounded),
|
||||
Text(embedContext.node.value.data as String),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../config/apiUrl.dart';
|
||||
import '../../routes/custom_appBar.dart';
|
||||
@ -66,11 +67,13 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
|
||||
setState(() {
|
||||
layoutColor = layoutString != null
|
||||
layoutColor =
|
||||
layoutString != null
|
||||
? Color(int.parse(layoutString))
|
||||
: Colors.redAccent;
|
||||
|
||||
bodyColor = bodyStringColor != null
|
||||
bodyColor =
|
||||
bodyStringColor != null
|
||||
? Color(int.parse(bodyStringColor))
|
||||
: Colors.white;
|
||||
});
|
||||
@ -99,7 +102,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
"created_by": null,
|
||||
"updated_by": null,
|
||||
"is_active": 1
|
||||
"is_active": 1,
|
||||
|
||||
// "org_id": orgId,
|
||||
// "created_by": userId,
|
||||
@ -144,10 +147,14 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
try {
|
||||
print("getUpdatedServices");
|
||||
|
||||
final result = await apiService.fetchOrganization();
|
||||
print("UUPdatedServices - $result");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final String? orgDataString = prefs.getString('org_data');
|
||||
|
||||
if (orgDataString != null) {
|
||||
final Map<String, dynamic> orgData = jsonDecode(orgDataString);
|
||||
print("UUPdatedServices - $orgData");
|
||||
setState(() {
|
||||
selectedOrg = result;
|
||||
selectedOrg = orgData;
|
||||
|
||||
String? rawLogoPath = selectedOrg?['logo'];
|
||||
if (rawLogoPath != null && rawLogoPath.contains('/assets')) {
|
||||
@ -158,16 +165,27 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
_orgNameController.text = selectedOrg?['name'];
|
||||
|
||||
layoutColor = selectedOrg?['layout_color'] != null
|
||||
? Color(int.parse(
|
||||
selectedOrg!['layout_color'].toString().replaceFirst('0x', ''),
|
||||
radix: 16))
|
||||
layoutColor =
|
||||
selectedOrg?['layout_color'] != null
|
||||
? Color(
|
||||
int.parse(
|
||||
selectedOrg!['layout_color'].toString().replaceFirst(
|
||||
'0x',
|
||||
'',
|
||||
),
|
||||
radix: 16,
|
||||
),
|
||||
)
|
||||
: Colors.white;
|
||||
|
||||
bodyColor = selectedOrg?['color'] != null
|
||||
? Color(int.parse(
|
||||
bodyColor =
|
||||
selectedOrg?['color'] != null
|
||||
? Color(
|
||||
int.parse(
|
||||
selectedOrg!['color'].toString().replaceFirst('0x', ''),
|
||||
radix: 16))
|
||||
radix: 16,
|
||||
),
|
||||
)
|
||||
: Colors.blue;
|
||||
|
||||
// Set mail config fields
|
||||
@ -200,12 +218,11 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
services = [];
|
||||
}
|
||||
|
||||
selectedServiceIds = services.map<Map<String, dynamic>>((item) {
|
||||
selectedServiceIds =
|
||||
services.map<Map<String, dynamic>>((item) {
|
||||
// force cast or copy to a regular map
|
||||
final map = Map<String, dynamic>.from(item);
|
||||
return {
|
||||
"service_id": map['service_id'].toString(),
|
||||
};
|
||||
return {"service_id": map['service_id'].toString()};
|
||||
}).toList();
|
||||
});
|
||||
|
||||
@ -213,6 +230,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
print("selectedOrg - $selectedOrg");
|
||||
print("mailConfig - $mailConfig");
|
||||
}
|
||||
|
||||
// final result = await apiService.fetchOrganization();
|
||||
} catch (e) {
|
||||
print('Error fetching updatedServices list: $e');
|
||||
}
|
||||
@ -222,10 +242,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
errorMessages.clear(); // Reset errors
|
||||
|
||||
// Required fields that must not be empty
|
||||
List<String> requiredFields = [
|
||||
"name",
|
||||
"description",
|
||||
];
|
||||
List<String> requiredFields = ["name", "description"];
|
||||
|
||||
// Check validation for each field
|
||||
for (String field in requiredFields) {
|
||||
@ -298,7 +315,26 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
print("✅ User submitted successfully!");
|
||||
print("📨 Response: ${response.body}");
|
||||
print("📨 Response Organizt Update: ${response.body}");
|
||||
|
||||
final data = json.decode(response.body);
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
// Make sure each item is a Map<String, dynamic>
|
||||
final Map<String, dynamic> orgList = Map<String, dynamic>.from(
|
||||
data['data'],
|
||||
);
|
||||
|
||||
print(orgList);
|
||||
await updateOrgDataWithNewValues(orgList);
|
||||
print("📨 Response Organizt Update:");
|
||||
// return orgList;
|
||||
|
||||
context.go('/listPlan');
|
||||
} else {
|
||||
print("❌ Submission failed. Status: ${response.statusCode}");
|
||||
@ -309,6 +345,27 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateOrgDataWithNewValues(Map<String, dynamic> newData) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final String? orgDataString = prefs.getString('org_data');
|
||||
|
||||
Map<String, dynamic> orgData = {};
|
||||
if (orgDataString != null) {
|
||||
try {
|
||||
orgData = jsonDecode(orgDataString);
|
||||
} catch (e) {
|
||||
print('❌ Failed to decode org_data: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Merge in the new data
|
||||
orgData.addAll(newData);
|
||||
|
||||
// Save back
|
||||
await prefs.setString('org_data', jsonEncode(orgData));
|
||||
print("✅ Updated org_data saved.");
|
||||
}
|
||||
|
||||
void handleSubmit() {
|
||||
print("HandleSubmiy - $orgData");
|
||||
createOrgData(orgData);
|
||||
@ -327,8 +384,10 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Scaffold(
|
||||
// backgroundColor: Colors.white,
|
||||
@ -336,23 +395,27 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
drawer: CustomDrawer(isDesktop: false),
|
||||
body: Padding(
|
||||
padding: isDesktop
|
||||
padding:
|
||||
isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width *
|
||||
horizontal:
|
||||
MediaQuery.of(context).size.width *
|
||||
0.1, // 30% of screen width as horizontal padding
|
||||
vertical: MediaQuery.of(context).size.height *
|
||||
vertical:
|
||||
MediaQuery.of(context).size.height *
|
||||
0, // 5% of screen height as vertical padding
|
||||
)
|
||||
: EdgeInsets.all(0),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
Expanded(child: buildOrganizationLayout(isDesktop))
|
||||
Expanded(child: buildOrganizationLayout(isDesktop)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildOrganizationLayout(isDesktop) {
|
||||
@ -382,18 +445,26 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
color: Colors.white,
|
||||
child: isDesktop
|
||||
child:
|
||||
isDesktop
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
// children: [Text("Button")],
|
||||
children:
|
||||
_buildSubmit(isDesktop, isViewMode, layoutColor),
|
||||
children: _buildSubmit(
|
||||
isDesktop,
|
||||
isViewMode,
|
||||
layoutColor,
|
||||
),
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children:
|
||||
_buildSubmit(isDesktop, isViewMode, layoutColor),
|
||||
))
|
||||
children: _buildSubmit(
|
||||
isDesktop,
|
||||
isViewMode,
|
||||
layoutColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -402,8 +473,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
Widget buildOrgLayout(bool isDesktop) {
|
||||
Future<void> _pickImage() async {
|
||||
final picker = ImagePicker();
|
||||
final XFile? pickedFile =
|
||||
await picker.pickImage(source: ImageSource.gallery);
|
||||
final XFile? pickedFile = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
);
|
||||
|
||||
if (pickedFile != null && kIsWeb) {
|
||||
try {
|
||||
@ -424,7 +496,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
// margin: isDesktop
|
||||
// ? EdgeInsets.all(10.0)
|
||||
// : EdgeInsets.only(left: 20.0, bottom: 20.0, top: 10.0, right: 20.0),
|
||||
height: isDesktop
|
||||
height:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.height * 0.98
|
||||
: MediaQuery.of(context).size.height,
|
||||
// decoration: BoxDecoration(
|
||||
@ -446,7 +519,11 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 20, right: 20, bottom: 20, top: 5),
|
||||
left: 20,
|
||||
right: 20,
|
||||
bottom: 20,
|
||||
top: 5,
|
||||
),
|
||||
// height: MediaQuery.of(context).size.height * 0.8,
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
@ -463,7 +540,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
? "Update Organization"
|
||||
: "Create Organization",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 15, fontWeight: FontWeight.w500),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -472,7 +551,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
color: Colors.white,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center, // now -> .center , old -> .start
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.center, // now -> .center , old -> .start
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 1.0),
|
||||
@ -481,7 +562,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF212121)),
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
@ -496,7 +578,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
decoration: InputDecoration(
|
||||
hintText: "Enter Organization Name",
|
||||
hintStyle: GoogleFonts.poppins(
|
||||
fontSize: 14, color: Colors.grey),
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior:
|
||||
FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
@ -510,7 +594,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
Spacer(),
|
||||
GestureDetector(
|
||||
onTap: _pickImage,
|
||||
child: _imageBytes != null
|
||||
child:
|
||||
_imageBytes != null
|
||||
? ClipOval(
|
||||
child: Image.memory(
|
||||
_imageBytes!,
|
||||
@ -527,8 +612,11 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
height: 75, // increased
|
||||
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) {
|
||||
errorBuilder: (
|
||||
context,
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
return const CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: Colors.redAccent,
|
||||
@ -547,30 +635,33 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
|
||||
Text(
|
||||
"Services",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF212121)),
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Color(0xFFF4F4FB)),
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
// color: bodyColor,
|
||||
// color: Color(0xFFF5F5F5),
|
||||
color: Colors.white),
|
||||
padding:
|
||||
EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 5),
|
||||
child: isDesktop
|
||||
color: Colors.white,
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: 5,
|
||||
right: 5,
|
||||
top: 15,
|
||||
bottom: 5,
|
||||
),
|
||||
child:
|
||||
isDesktop
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
@ -579,15 +670,11 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
: Expanded(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: _buildOptions(),
|
||||
child: Row(children: _buildOptions()),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -597,7 +684,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF212121)),
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
@ -606,18 +694,26 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
// color: Color(0xFFF4F4FB),
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: 5, right: 5, top: 15, bottom: 5),
|
||||
child: layoutColor != null && bodyColor != null
|
||||
left: 5,
|
||||
right: 5,
|
||||
top: 15,
|
||||
bottom: 5,
|
||||
),
|
||||
child:
|
||||
layoutColor != null && bodyColor != null
|
||||
? ColorThemePickerWidget(
|
||||
initialLayoutColor: layoutColor,
|
||||
initialBodyColor: bodyColor,
|
||||
onLayoutColorSelected:
|
||||
(Color selectedLayoutColor) {
|
||||
onLayoutColorSelected: (
|
||||
Color selectedLayoutColor,
|
||||
) {
|
||||
setState(() {
|
||||
layoutColor = selectedLayoutColor;
|
||||
});
|
||||
},
|
||||
onBodyColorSelected: (Color selectedBodyColor) {
|
||||
onBodyColorSelected: (
|
||||
Color selectedBodyColor,
|
||||
) {
|
||||
setState(() {
|
||||
bodyColor = selectedBodyColor;
|
||||
});
|
||||
@ -628,9 +724,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
@ -643,7 +737,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF212121)),
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
|
||||
// GestureDetector(
|
||||
@ -660,11 +755,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
// ),
|
||||
],
|
||||
),
|
||||
// if (showMail)
|
||||
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
// if (showMail)
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
// width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
@ -678,7 +771,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
// color: Color(0xFFF5F5F5),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: isDesktop
|
||||
mainAxisAlignment:
|
||||
isDesktop
|
||||
? MainAxisAlignment.start
|
||||
: MainAxisAlignment.center,
|
||||
children: [
|
||||
@ -688,17 +782,18 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
initialMailData: mailConfig,
|
||||
onMailDataChanged: (updatedData) {
|
||||
// You can setState here or do something else with updatedData
|
||||
print(
|
||||
"Updated Mail Data: $updatedData");
|
||||
print("Updated Mail Data: $updatedData");
|
||||
|
||||
mailConfig = updatedData;
|
||||
},
|
||||
)
|
||||
: CircularProgressIndicator(),
|
||||
],
|
||||
))
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
// isDesktop
|
||||
// ? Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.end,
|
||||
@ -738,8 +833,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
String serviceId = service['service_id'].toString();
|
||||
// bool isSelected = selectedServiceIds.contains(serviceId);
|
||||
bool isSelected =
|
||||
selectedServiceIds.any((item) => item["service_id"] == serviceId);
|
||||
bool isSelected = selectedServiceIds.any(
|
||||
(item) => item["service_id"] == serviceId,
|
||||
);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
@ -747,8 +843,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
String serviceId = service['service_id'].toString();
|
||||
|
||||
// Check if already selected
|
||||
int existingIndex = selectedServiceIds
|
||||
.indexWhere((item) => item["service_id"] == serviceId);
|
||||
int existingIndex = selectedServiceIds.indexWhere(
|
||||
(item) => item["service_id"] == serviceId,
|
||||
);
|
||||
|
||||
if (existingIndex != -1) {
|
||||
selectedServiceIds.removeAt(existingIndex);
|
||||
@ -757,24 +854,30 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Row(children: [
|
||||
child: Row(
|
||||
children: [
|
||||
iconUrl.isNotEmpty
|
||||
? Image.network(
|
||||
iconUrl,
|
||||
width: 18,
|
||||
height: 18,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Icon(fallbackIcon,
|
||||
size: 18,
|
||||
color: isSelected == name
|
||||
? Color(0xFF114D8B)
|
||||
: Color(0xFF475569));
|
||||
},
|
||||
)
|
||||
: Icon(fallbackIcon,
|
||||
return Icon(
|
||||
fallbackIcon,
|
||||
size: 18,
|
||||
color:
|
||||
isSelected == name ? Color(0xFF114D8B) : Color(0xFF475569)),
|
||||
isSelected == name
|
||||
? Color(0xFF114D8B)
|
||||
: Color(0xFF475569),
|
||||
);
|
||||
},
|
||||
)
|
||||
: Icon(
|
||||
fallbackIcon,
|
||||
size: 18,
|
||||
color:
|
||||
isSelected == name ? Color(0xFF114D8B) : Color(0xFF475569),
|
||||
),
|
||||
|
||||
SizedBox(width: 2),
|
||||
|
||||
@ -784,7 +887,8 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
fontSize: 12,
|
||||
color: isSelected == name ? Color(0xFF114D8B) : Color(0xFF475569),
|
||||
fontWeight:
|
||||
isSelected == name ? FontWeight.bold : FontWeight.w500),
|
||||
isSelected == name ? FontWeight.bold : FontWeight.w500,
|
||||
),
|
||||
// fontWeight: selectedListOption == title ? FontWeight.bold : FontWeight.normal,)),
|
||||
),
|
||||
|
||||
@ -796,15 +900,19 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.green : Colors.grey, width: 1),
|
||||
color: isSelected ? Colors.green : Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_circle,
|
||||
size: 10,
|
||||
color: isSelected ? Colors.green : Colors.grey,
|
||||
// color: Colors.grey,
|
||||
)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -848,13 +956,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
onPressed: () {
|
||||
context.go('/listPlan');
|
||||
},
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
)),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
child: Text("Cancel", style: GoogleFonts.poppins(fontSize: 12)),
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
MouseRegion(
|
||||
// cursor: widget.isViewMode
|
||||
// ? SystemMouseCursors.forbidden
|
||||
@ -873,12 +977,9 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
onPressed: handleSubmit, // Disable when in view mode
|
||||
child: Text(
|
||||
"Submit",
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
child: Text("Submit", style: GoogleFonts.poppins(fontSize: 12)),
|
||||
),
|
||||
),
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
"employeeCode",
|
||||
"dateOfIssue",
|
||||
"dateOfExpiry",
|
||||
"changePassword"
|
||||
"changePassword",
|
||||
];
|
||||
|
||||
Color? layoutColor;
|
||||
@ -197,7 +197,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
// apiUserData = users;
|
||||
|
||||
print("Total users fetched from API: ${users.length}");
|
||||
|
||||
// user["role_id"] != "5" - Travel Agent
|
||||
apiUserData = users.where((user) => user["role_id"] != "5").toList();
|
||||
print("Total users fetched from API1: ${apiUserData?.length}");
|
||||
print("APIUSerDATa - $apiUserData");
|
||||
@ -206,7 +206,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
userMap = {
|
||||
for (var user in userList)
|
||||
user['user_id'].toString():
|
||||
"${user['first_name']} ${user['last_name']}"
|
||||
"${user['first_name']} ${user['last_name']}",
|
||||
};
|
||||
userIdsApi = userMap.keys.toList();
|
||||
});
|
||||
@ -240,7 +240,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
|
||||
groupMap = {
|
||||
for (var group in groupList)
|
||||
group['group_id'].toString(): group['name'].toString().trim()
|
||||
group['group_id'].toString(): group['name'].toString().trim(),
|
||||
};
|
||||
|
||||
userIdsApi = groupMap.keys.toList();
|
||||
@ -265,23 +265,12 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
_buildFirstRow(widget.isDesktop),
|
||||
if (widget.isDesktop)
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
if (widget.isDesktop) SizedBox(height: 10),
|
||||
_buildSecondRow(widget.isDesktop),
|
||||
if (widget.isDesktop)
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Divider(
|
||||
thickness: 0.2,
|
||||
color: Colors.blueGrey.shade100,
|
||||
),
|
||||
if (widget.isDesktop) SizedBox(height: 10),
|
||||
Divider(thickness: 0.2, color: Colors.blueGrey.shade100),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@ -294,9 +283,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
_buildThirdRow(widget.isDesktop),
|
||||
],
|
||||
),
|
||||
@ -306,7 +293,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
Widget _buildFirstRow(bool isDesktop) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: widget.isDesktop
|
||||
child:
|
||||
widget.isDesktop
|
||||
? Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -333,7 +321,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
Widget _buildSecondRow(bool isDesktop) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: widget.isDesktop
|
||||
child:
|
||||
widget.isDesktop
|
||||
? Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -360,7 +349,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
Widget _buildThirdRow(bool isDesktop) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: widget.isDesktop
|
||||
child:
|
||||
widget.isDesktop
|
||||
? Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -369,10 +359,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
buildDelegationStartDateField(isDesktop),
|
||||
Spacer(), // Space after Last Name
|
||||
buildDelegationEndDateField(isDesktop),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
buildReset(isDesktop)
|
||||
SizedBox(width: 15),
|
||||
buildReset(isDesktop),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
@ -383,7 +371,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
buildDelegationStartDateField(isDesktop),
|
||||
SizedBox(height: 8),
|
||||
buildDelegationEndDateField(isDesktop),
|
||||
buildReset(isDesktop)
|
||||
buildReset(isDesktop),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -398,7 +386,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -415,8 +404,10 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: "Employee Code",
|
||||
labelStyle:
|
||||
GoogleFonts.poppins(fontSize: 12, color: Colors.grey),
|
||||
labelStyle: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||
@ -444,7 +435,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -458,10 +450,12 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(fontSize: 12, color: Colors.black),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(horizontal: 10), // Proper padding
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
), // Proper padding
|
||||
),
|
||||
onChanged: widget.isViewMode
|
||||
onChanged:
|
||||
widget.isViewMode
|
||||
? null
|
||||
: (newValue) {
|
||||
setState(() {
|
||||
@ -469,7 +463,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
});
|
||||
widget.onDepartmentChanged?.call(newValue);
|
||||
},
|
||||
items: apiCostData?.map<DropdownMenuItem<String>>((item) {
|
||||
items:
|
||||
apiCostData?.map<DropdownMenuItem<String>>((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item['department_id'], // ID as value
|
||||
child: Text(item['name'] ?? "Unknown"),
|
||||
@ -496,9 +491,11 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
|
||||
// CustomTextFieldUserWrapper(
|
||||
// isFocused: false,
|
||||
// isDesktop: widget.isDesktop,
|
||||
@ -542,13 +539,13 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
CustomTextFieldUserWrapper(
|
||||
isFocused: false,
|
||||
isDesktop: widget.isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: apiAllGroups == null
|
||||
child:
|
||||
apiAllGroups == null
|
||||
? Center(
|
||||
child: Transform.scale(
|
||||
scale: 0.5,
|
||||
@ -566,41 +563,44 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search Group...",
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 10),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// items: apiAllGroups!.map((group) {
|
||||
// return "${group['name']} ";
|
||||
// }).toList(),
|
||||
|
||||
items: apiAllGroups!.map((group) {
|
||||
return group['name'].toString().trim(); // <-- trim spaces
|
||||
items:
|
||||
apiAllGroups!.map((group) {
|
||||
return group['name']
|
||||
.toString()
|
||||
.trim(); // <-- trim spaces
|
||||
}).toList(),
|
||||
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
dropdownSearchDecoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 1,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
selectedItem ?? "Select",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
),
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
),
|
||||
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue == null) return;
|
||||
|
||||
final levelId = groupMap.entries
|
||||
final levelId =
|
||||
groupMap.entries
|
||||
.firstWhere((entry) => entry.value == newValue)
|
||||
.key;
|
||||
|
||||
@ -608,8 +608,9 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
selectedLevel = levelId;
|
||||
});
|
||||
|
||||
widget.onLevelChanged
|
||||
?.call(levelId); // ✅ pass the ID not the name
|
||||
widget.onLevelChanged?.call(
|
||||
levelId,
|
||||
); // ✅ pass the ID not the name
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -636,8 +637,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -645,7 +646,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
isDesktop: isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: apiUserData == null
|
||||
child:
|
||||
apiUserData == null
|
||||
? Center(
|
||||
child: Transform.scale(
|
||||
scale: 0.5,
|
||||
@ -662,12 +664,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search User...",
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
items: apiUserData!.map((user) {
|
||||
),
|
||||
items:
|
||||
apiUserData!.map((user) {
|
||||
return "${user['first_name']} ${user['last_name']}";
|
||||
}).toList(),
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
@ -678,7 +682,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@ -688,6 +693,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// onChanged: (String? newValue) {
|
||||
// setState(() {
|
||||
// selectedFirstApprover = userMap.entries
|
||||
@ -701,13 +707,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
// });
|
||||
// widget.onFirstApproverChanged?.call(newValue);
|
||||
// },
|
||||
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue == null) return;
|
||||
|
||||
final approverId = userMap.entries
|
||||
final approverId =
|
||||
userMap.entries
|
||||
.firstWhere(
|
||||
(entry) => entry.value == newValue)
|
||||
(entry) => entry.value == newValue,
|
||||
)
|
||||
.key;
|
||||
|
||||
setState(() {
|
||||
@ -715,7 +722,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
});
|
||||
|
||||
widget.onFirstApproverChanged?.call(
|
||||
approverId); // ✅ not newValue, but approverId
|
||||
approverId,
|
||||
); // ✅ not newValue, but approverId
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -749,8 +757,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -758,7 +766,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
isDesktop: isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: apiUserData == null
|
||||
child:
|
||||
apiUserData == null
|
||||
? Center(
|
||||
child: Transform.scale(
|
||||
scale: 0.5,
|
||||
@ -775,12 +784,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search User...",
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
items: apiUserData!.map((user) {
|
||||
),
|
||||
items:
|
||||
apiUserData!.map((user) {
|
||||
return "${user['first_name']} ${user['last_name']}";
|
||||
}).toList(),
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
@ -791,7 +802,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@ -805,9 +817,11 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue == null) return;
|
||||
|
||||
final approverId = userMap.entries
|
||||
final approverId =
|
||||
userMap.entries
|
||||
.firstWhere(
|
||||
(entry) => entry.value == newValue)
|
||||
(entry) => entry.value == newValue,
|
||||
)
|
||||
.key;
|
||||
|
||||
setState(() {
|
||||
@ -815,7 +829,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
});
|
||||
|
||||
widget.onSecondApproverChanged?.call(
|
||||
approverId); // ✅ not newValue, but approverId
|
||||
approverId,
|
||||
); // ✅ not newValue, but approverId
|
||||
},
|
||||
// onChanged: (String? newValue) {
|
||||
// setState(() {
|
||||
@ -845,9 +860,9 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
Widget buildApprover3(bool isDesktop) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
|
||||
// child: Expanded(
|
||||
// Allow second column to take available space
|
||||
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -861,8 +876,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -870,7 +885,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
isDesktop: isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: apiUserData == null
|
||||
child:
|
||||
apiUserData == null
|
||||
? Center(
|
||||
child: Transform.scale(
|
||||
scale: 0.5,
|
||||
@ -887,12 +903,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search User...",
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
items: apiUserData!.map((user) {
|
||||
),
|
||||
items:
|
||||
apiUserData!.map((user) {
|
||||
return "${user['first_name']} ${user['last_name']}";
|
||||
}).toList(),
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
@ -903,7 +921,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@ -916,9 +935,11 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue == null) return;
|
||||
|
||||
final approverId = userMap.entries
|
||||
final approverId =
|
||||
userMap.entries
|
||||
.firstWhere(
|
||||
(entry) => entry.value == newValue)
|
||||
(entry) => entry.value == newValue,
|
||||
)
|
||||
.key;
|
||||
|
||||
setState(() {
|
||||
@ -926,7 +947,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
});
|
||||
|
||||
widget.onThirdApproverChanged?.call(
|
||||
approverId); // ✅ not newValue, but approverId
|
||||
approverId,
|
||||
); // ✅ not newValue, but approverId
|
||||
},
|
||||
// onChanged: (String? newValue) {
|
||||
// setState(() {
|
||||
@ -972,8 +994,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -981,7 +1003,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
isDesktop: isDesktop,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: apiUserData == null
|
||||
child:
|
||||
apiUserData == null
|
||||
? Center(
|
||||
child: Transform.scale(
|
||||
scale: 0.5,
|
||||
@ -990,7 +1013,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
)
|
||||
: DropdownSearch<String>(
|
||||
// selectedItem: userMap[selectedSubstituteApprover],
|
||||
selectedItem: selectedSubstituteApprover != null
|
||||
selectedItem:
|
||||
selectedSubstituteApprover != null
|
||||
? userMap[selectedSubstituteApprover]
|
||||
: null,
|
||||
enabled: !widget.isViewMode,
|
||||
@ -1001,12 +1025,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
searchFieldProps: TextFieldProps(
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search User...",
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
items: apiUserData!.map((user) {
|
||||
),
|
||||
items:
|
||||
apiUserData!.map((user) {
|
||||
return "${user['first_name']} ${user['last_name']}";
|
||||
}).toList(),
|
||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||
@ -1017,7 +1043,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) => Align(
|
||||
dropdownBuilder:
|
||||
(context, selectedItem) => Align(
|
||||
// Center-align selected item
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@ -1027,6 +1054,7 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// onChanged: (String? newValue) {
|
||||
// setState(() {
|
||||
// selectedFirstApprover = userMap.entries
|
||||
@ -1040,13 +1068,14 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
// });
|
||||
// widget.onFirstApproverChanged?.call(newValue);
|
||||
// },
|
||||
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue == null) return;
|
||||
|
||||
final approverId = userMap.entries
|
||||
final approverId =
|
||||
userMap.entries
|
||||
.firstWhere(
|
||||
(entry) => entry.value == newValue)
|
||||
(entry) => entry.value == newValue,
|
||||
)
|
||||
.key;
|
||||
|
||||
setState(() {
|
||||
@ -1054,7 +1083,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
});
|
||||
|
||||
widget.onFirstSubsApproverChanged?.call(
|
||||
approverId); // ✅ not newValue, but approverId
|
||||
approverId,
|
||||
); // ✅ not newValue, but approverId
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -1095,7 +1125,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
|
||||
DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedCheckOutDate != null &&
|
||||
initialDate:
|
||||
_selectedCheckOutDate != null &&
|
||||
_selectedCheckOutDate!.isAfter(today)
|
||||
? _selectedCheckOutDate!
|
||||
: today,
|
||||
@ -1106,8 +1137,9 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
|
||||
setState(() {
|
||||
_selectedCheckOutDate = pickedDate;
|
||||
widget.controllers["delegationStartDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(pickedDate);
|
||||
widget.controllers["delegationStartDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(pickedDate);
|
||||
|
||||
if (_selectedEndDate != null &&
|
||||
_selectedEndDate!.isBefore(_selectedCheckOutDate!)) {
|
||||
@ -1126,8 +1158,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -1149,13 +1181,18 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Select Date",
|
||||
labelStyle:
|
||||
const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
labelStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 16),
|
||||
suffixIcon: const Icon(Icons.calendar_today,
|
||||
size: 16, color: Colors.grey),
|
||||
suffixIcon: const Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1179,9 +1216,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
DateTime minDate = _selectedCheckOutDate != null
|
||||
? _selectedCheckOutDate!
|
||||
: today;
|
||||
DateTime minDate =
|
||||
_selectedCheckOutDate != null ? _selectedCheckOutDate! : today;
|
||||
|
||||
// Parse date from notifier if available, else use today
|
||||
DateTime initialDate;
|
||||
@ -1198,8 +1234,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
|
||||
DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedEndDate != null &&
|
||||
_selectedEndDate!.isAfter(minDate)
|
||||
initialDate:
|
||||
_selectedEndDate != null && _selectedEndDate!.isAfter(minDate)
|
||||
? _selectedEndDate!
|
||||
: minDate,
|
||||
firstDate: minDate,
|
||||
@ -1209,8 +1245,9 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
if (pickedDate != null && pickedDate != _selectedEndDate) {
|
||||
setState(() {
|
||||
_selectedEndDate = pickedDate;
|
||||
widget.controllers["delegationEndDate"]?.text =
|
||||
DateFormat('dd-MM-yyyy').format(pickedDate);
|
||||
widget.controllers["delegationEndDate"]?.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(pickedDate);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1223,8 +1260,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF575A74))
|
||||
|
||||
color: Color(0xFF575A74),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldUserWrapper(
|
||||
@ -1247,13 +1284,18 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Select Date",
|
||||
labelStyle:
|
||||
const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
labelStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 16),
|
||||
suffixIcon: const Icon(Icons.calendar_today,
|
||||
size: 16, color: Colors.grey),
|
||||
suffixIcon: const Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1279,7 +1321,10 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
Text(
|
||||
"",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12, fontWeight: FontWeight.w400, color: Colors.black),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
ElevatedButton(
|
||||
@ -1296,10 +1341,8 @@ class _OfficeDetailsState extends State<OfficeDetails> {
|
||||
onPressed: () {
|
||||
handleReset();
|
||||
},
|
||||
child: Text(
|
||||
"Reset",
|
||||
style: GoogleFonts.poppins(fontSize: 11),
|
||||
))
|
||||
child: Text("Reset", style: GoogleFonts.poppins(fontSize: 11)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -313,6 +313,8 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
(user['role_value']?.toLowerCase().contains(lowerQuery) ??
|
||||
false);
|
||||
}).toList();
|
||||
|
||||
currentPage = 0;
|
||||
});
|
||||
print("filteredPlans: $filteredUsers");
|
||||
}
|
||||
|
||||
@ -2,9 +2,10 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
// import 'package:flutter/rendering.dart';
|
||||
import 'dart:html' as html;
|
||||
import 'package:frontend/config/apiUrl.dart'; // 1 newly added
|
||||
import 'package:frontend/services/apiService.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
@ -23,13 +24,14 @@ class MyApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
final ApiService apiService = ApiService();
|
||||
String? _authCode;
|
||||
String? userRole;
|
||||
bool _isAuthRedirect = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
||||
// SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
||||
if (kIsWeb) {
|
||||
final uri = Uri.parse(html.window.location.href);
|
||||
if (uri.path == '/authredirection' &&
|
||||
@ -119,6 +121,7 @@ class _MyAppState extends State<MyApp> {
|
||||
print("userData11 - ${userData['role']}");
|
||||
print("userData12 - $userRole");
|
||||
}
|
||||
apiService.getOrganizationData();
|
||||
} catch (e) {
|
||||
print('Error decoding token: $e');
|
||||
}
|
||||
|
||||
@ -1,18 +1,13 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frontend/config/apiUrl.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart'; // don't forget
|
||||
import '../services/apiService.dart';
|
||||
import '../utils/auth_utils.dart';
|
||||
|
||||
enum TabSelection {
|
||||
dashboard,
|
||||
allTrips,
|
||||
myTrips,
|
||||
myApprovals,
|
||||
allMenu,
|
||||
}
|
||||
enum TabSelection { dashboard, allTrips, myTrips, myApprovals, allMenu }
|
||||
|
||||
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
final bool isDesktop;
|
||||
@ -131,6 +126,64 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
}
|
||||
|
||||
Future<void> getOrganizationData() async {
|
||||
try {
|
||||
print("getUpdatedServices");
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final String? orgDataString = prefs.getString('org_data');
|
||||
|
||||
if (orgDataString != null) {
|
||||
// final result = await apiService.fetchOrganization();
|
||||
|
||||
final Map<String, dynamic> result = jsonDecode(orgDataString);
|
||||
print("UUPdatedServices - $result");
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
print("UUPdatedServices - $result");
|
||||
|
||||
setState(() {
|
||||
selectedOrg = result;
|
||||
|
||||
layoutColor =
|
||||
selectedOrg?['layout_color'] != null
|
||||
? Color(int.parse(selectedOrg!['layout_color']))
|
||||
: Colors.white;
|
||||
|
||||
bodyColor =
|
||||
selectedOrg?['color'] != null
|
||||
? Color(
|
||||
int.parse(
|
||||
selectedOrg!['color'].toString().replaceFirst('0x', ''),
|
||||
radix: 16,
|
||||
),
|
||||
)
|
||||
: Colors.blue;
|
||||
|
||||
String? rawLogoPath = selectedOrg?['logo'];
|
||||
if (rawLogoPath != null && rawLogoPath.contains('/assets')) {
|
||||
const baseUrl = apiUrl;
|
||||
|
||||
// const baseUrl = "https://apitest.tripapprovaltool.com";
|
||||
final assetPath = rawLogoPath.split('/assets').last;
|
||||
selectedOrg!['logo'] = "$baseUrl/assets$assetPath";
|
||||
}
|
||||
});
|
||||
|
||||
// Save to SharedPreferences
|
||||
await prefs.setString('layout_color', selectedOrg?['layout_color']);
|
||||
await prefs.setString('body_color', selectedOrg?['color']);
|
||||
await prefs.setString('body_color', selectedOrg?['plan_action']);
|
||||
|
||||
print(
|
||||
"Layout Color- ${selectedOrg?['layout_color']} - $layoutColor ---------- bodyColor - $bodyColor",
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error : $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getOrganizationData1() async {
|
||||
try {
|
||||
print("getUpdatedServices");
|
||||
|
||||
@ -142,14 +195,19 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
setState(() {
|
||||
selectedOrg = result;
|
||||
|
||||
layoutColor = selectedOrg?['layout_color'] != null
|
||||
layoutColor =
|
||||
selectedOrg?['layout_color'] != null
|
||||
? Color(int.parse(selectedOrg!['layout_color']))
|
||||
: Colors.white;
|
||||
|
||||
bodyColor = selectedOrg?['color'] != null
|
||||
? Color(int.parse(
|
||||
bodyColor =
|
||||
selectedOrg?['color'] != null
|
||||
? Color(
|
||||
int.parse(
|
||||
selectedOrg!['color'].toString().replaceFirst('0x', ''),
|
||||
radix: 16))
|
||||
radix: 16,
|
||||
),
|
||||
)
|
||||
: Colors.blue;
|
||||
|
||||
String? rawLogoPath = selectedOrg?['logo'];
|
||||
@ -166,22 +224,32 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
await prefs.setString('body_color', selectedOrg?['plan_action']);
|
||||
|
||||
print(
|
||||
"Layout Color- ${selectedOrg?['layout_color']} - $layoutColor ---------- bodyColor - $bodyColor");
|
||||
"Layout Color- ${selectedOrg?['layout_color']} - $layoutColor ---------- bodyColor - $bodyColor",
|
||||
);
|
||||
} catch (e) {
|
||||
print("Error : $e");
|
||||
}
|
||||
}
|
||||
|
||||
// void handleTabChange(TabSelection tab, String route) {
|
||||
// final currentUri =
|
||||
// GoRouterState.of(context).uri.toString(); // ✅ safer than `.location`
|
||||
// print("currentUri - $currentUri");
|
||||
//
|
||||
// if (currentUri != route) {
|
||||
// setState(() {
|
||||
// selectedTab = tab;
|
||||
// });
|
||||
// context.go(route);
|
||||
// }
|
||||
// }
|
||||
|
||||
void handleTabChange(TabSelection tab, String route) {
|
||||
final currentUri =
|
||||
GoRouterState.of(context).uri.toString(); // ✅ safer than `.location`
|
||||
print("currentUri - $currentUri");
|
||||
final currentUri = GoRouterState.of(context).uri.toString();
|
||||
|
||||
if (currentUri != route) {
|
||||
setState(() {
|
||||
selectedTab = tab;
|
||||
});
|
||||
context.go(route);
|
||||
context.go(route); // 🔄 Let navigation happen
|
||||
// The tab selection will automatically be updated by didChangeDependencies
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,18 +293,21 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
|
||||
titleSpacing: 0,
|
||||
|
||||
title: !widget.isDesktop
|
||||
title:
|
||||
!widget.isDesktop
|
||||
? Text('')
|
||||
: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.05),
|
||||
horizontal: MediaQuery.of(context).size.width * 0.05,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
|
||||
|
||||
child: selectedOrg?['logo'] != null
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
|
||||
child:
|
||||
selectedOrg?['logo'] != null
|
||||
? SizedBox(
|
||||
height: 60,
|
||||
child: ClipRect(
|
||||
@ -253,7 +324,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
);
|
||||
},
|
||||
),
|
||||
))
|
||||
),
|
||||
)
|
||||
: const CircleAvatar(
|
||||
radius: 20,
|
||||
// backgroundColor: Colors.white,
|
||||
@ -264,9 +336,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.18,
|
||||
),
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.18),
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width * 0.35,
|
||||
child: Row(
|
||||
@ -277,7 +347,9 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
buildNavItem(
|
||||
"Dashboard",
|
||||
() => handleTabChange(
|
||||
TabSelection.dashboard, '/StatusDashboard'),
|
||||
TabSelection.dashboard,
|
||||
'/StatusDashboard',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.dashboard,
|
||||
icon: Icons.dashboard,
|
||||
@ -291,7 +363,9 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
buildNavItem(
|
||||
"All Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.allTrips, '/listAllPlan'),
|
||||
TabSelection.allTrips,
|
||||
'/listAllPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.allTrips,
|
||||
icon: Icons.format_list_bulleted_rounded,
|
||||
@ -303,7 +377,9 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
buildNavItem(
|
||||
"Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips, '/listTravelAgentPlan'),
|
||||
TabSelection.myTrips,
|
||||
'/listTravelAgentPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listTravelAgentPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
@ -314,7 +390,9 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
buildNavItem(
|
||||
"My Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips, '/listPlan'),
|
||||
TabSelection.myTrips,
|
||||
'/listPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
@ -326,10 +404,13 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
"My Approvals",
|
||||
|
||||
() => handleTabChange(
|
||||
TabSelection.myApprovals, '/ApprovalList'),
|
||||
TabSelection.myApprovals,
|
||||
'/ApprovalList',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/ApprovalList'),
|
||||
isSelected: selectedTab == TabSelection.myApprovals,
|
||||
isSelected:
|
||||
selectedTab == TabSelection.myApprovals,
|
||||
icon: Icons.verified_outlined,
|
||||
),
|
||||
],
|
||||
@ -342,12 +423,14 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
actions: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.05),
|
||||
horizontal: MediaQuery.of(context).size.width * 0.05,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (userData?["role"] != "User")
|
||||
Builder(
|
||||
builder: (context) => PopupMenuButton<String>(
|
||||
builder:
|
||||
(context) => PopupMenuButton<String>(
|
||||
color: Colors.white,
|
||||
padding: EdgeInsets.zero,
|
||||
offset: const Offset(0, 50), // 👈 shift it 50 pixels down
|
||||
@ -394,20 +477,23 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
|
||||
// itemBuilder: (BuildContext context) =>
|
||||
// menuItems.map(buildMenuItem).toList(),
|
||||
|
||||
itemBuilder: (BuildContext context) {
|
||||
// final isUser = userData?["role"] == "User";
|
||||
final role = userData?["role"];
|
||||
List<Map<String, dynamic>> filteredItems;
|
||||
|
||||
if (role == "User") {
|
||||
filteredItems = menuItems
|
||||
.where((item) =>
|
||||
filteredItems =
|
||||
menuItems
|
||||
.where(
|
||||
(item) =>
|
||||
item['value'] == '/CreateUserDetails' ||
|
||||
item['value'] == '/logout')
|
||||
item['value'] == '/logout',
|
||||
)
|
||||
.toList();
|
||||
} else if (role == "Travel Agent") {
|
||||
filteredItems = menuItems
|
||||
filteredItems =
|
||||
menuItems
|
||||
.where((item) => item['value'] == '/logout')
|
||||
.toList();
|
||||
} else {
|
||||
@ -497,12 +583,12 @@ final List<Map<String, dynamic>> menuItems = [
|
||||
{
|
||||
'value': '/OrganizationSettings',
|
||||
'icon': Icons.business,
|
||||
'label': 'Org Management'
|
||||
'label': 'Org Management',
|
||||
},
|
||||
{
|
||||
'value': '/listUser',
|
||||
'icon': Icons.manage_accounts,
|
||||
'label': 'User Management'
|
||||
'label': 'User Management',
|
||||
},
|
||||
|
||||
// {'value': '/group', 'icon': Icons.group, 'label': 'Group'},
|
||||
@ -518,7 +604,7 @@ final List<Map<String, dynamic>> menuItems = [
|
||||
{
|
||||
'value': '/CreateUserDetails',
|
||||
'icon': Icons.account_circle,
|
||||
'label': 'My Profile'
|
||||
'label': 'My Profile',
|
||||
},
|
||||
{'value': '/logout', 'icon': Icons.login_outlined, 'label': 'Logout'},
|
||||
];
|
||||
@ -527,12 +613,16 @@ PopupMenuItem<String> buildMenuItem(Map<String, dynamic> item) {
|
||||
return PopupMenuItem<String>(
|
||||
height: 40, // 👈 reduce PopupMenuItem height
|
||||
value: item['value'],
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 12), // 👈 control left-right spacing
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
), // 👈 control left-right spacing
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(item['icon'],
|
||||
size: 18, color: Colors.black87), // 👈 smaller, cleaner icon
|
||||
Icon(
|
||||
item['icon'],
|
||||
size: 18,
|
||||
color: Colors.black87,
|
||||
), // 👈 smaller, cleaner icon
|
||||
SizedBox(width: 10), // 👈 small space between icon and text
|
||||
Text(
|
||||
item['label'],
|
||||
@ -547,8 +637,13 @@ PopupMenuItem<String> buildMenuItem(Map<String, dynamic> item) {
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildNavItem(String label, VoidCallback onTap, Color? layoutColor,
|
||||
{bool isSelected = true, IconData? icon}) {
|
||||
Widget buildNavItem(
|
||||
String label,
|
||||
VoidCallback onTap,
|
||||
Color? layoutColor, {
|
||||
bool isSelected = true,
|
||||
IconData? icon,
|
||||
}) {
|
||||
final effectiveColor =
|
||||
isSelected ? (layoutColor ?? Colors.blue) : Colors.black;
|
||||
|
||||
@ -587,7 +682,8 @@ Widget buildNavItem(String label, VoidCallback onTap, Color? layoutColor,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
height: 2,
|
||||
width: isSelected
|
||||
width:
|
||||
isSelected
|
||||
? 50
|
||||
: 0, // Animate width (make sure isSelected changes)
|
||||
color: effectiveColor,
|
||||
|
||||
@ -84,7 +84,14 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
try {
|
||||
print("getUpdatedServices");
|
||||
|
||||
final result = await apiService.fetchOrganization();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final String? orgDataString = prefs.getString('org_data');
|
||||
|
||||
if (orgDataString != null) {
|
||||
// final result = await apiService.fetchOrganization();
|
||||
|
||||
final Map<String, dynamic> result = jsonDecode(orgDataString);
|
||||
print("UUPdatedServices - $result");
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
print("UUPdatedServices - $result");
|
||||
@ -92,14 +99,19 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
setState(() {
|
||||
selectedOrg = result;
|
||||
|
||||
layoutColor = selectedOrg?['layout_color'] != null
|
||||
layoutColor =
|
||||
selectedOrg?['layout_color'] != null
|
||||
? Color(int.parse(selectedOrg!['layout_color']))
|
||||
: Colors.white;
|
||||
|
||||
bodyColor = selectedOrg?['color'] != null
|
||||
? Color(int.parse(
|
||||
bodyColor =
|
||||
selectedOrg?['color'] != null
|
||||
? Color(
|
||||
int.parse(
|
||||
selectedOrg!['color'].toString().replaceFirst('0x', ''),
|
||||
radix: 16))
|
||||
radix: 16,
|
||||
),
|
||||
)
|
||||
: Colors.blue;
|
||||
|
||||
String? rawLogoPath = selectedOrg?['logo'];
|
||||
@ -116,7 +128,9 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
await prefs.setString('body_color', selectedOrg?['plan_action']);
|
||||
|
||||
print(
|
||||
"Layout Color- ${selectedOrg?['layout_color']} - $layoutColor ---------- bodyColor - $bodyColor");
|
||||
"Layout Color- ${selectedOrg?['layout_color']} - $layoutColor ---------- bodyColor - $bodyColor",
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error : $e");
|
||||
}
|
||||
@ -126,7 +140,6 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
Widget build(BuildContext context) {
|
||||
Widget drawerContent = Container(
|
||||
// color: Colors.white,
|
||||
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
@ -169,29 +182,49 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// _buildDrawerItem(context, Icons.home_outlined, 'Home', '/home'),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
Icons.dashboard,
|
||||
'Dashboard',
|
||||
'/StatusDashboard',
|
||||
),
|
||||
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
_buildDrawerItem(context, Icons.dashboard, 'Dashboard',
|
||||
'/StatusDashboard'),
|
||||
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
_buildDrawerItem(context, Icons.insights_outlined, 'All Trips',
|
||||
'/listAllPlan'),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
Icons.insights_outlined,
|
||||
'All Trips',
|
||||
'/listAllPlan',
|
||||
),
|
||||
|
||||
if (userDetails["role"] == "Travel Agent")
|
||||
_buildDrawerItem(context, Icons.assessment_outlined,
|
||||
'My Approvals', '/listTravelAgentPlan'),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
Icons.assessment_outlined,
|
||||
'My Approvals',
|
||||
'/listTravelAgentPlan',
|
||||
),
|
||||
|
||||
if (userDetails["role"] != "Travel Agent")
|
||||
_buildDrawerItem(context, Icons.request_page_outlined, 'My Trips',
|
||||
'/listPlan'),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
Icons.request_page_outlined,
|
||||
'My Trips',
|
||||
'/listPlan',
|
||||
),
|
||||
|
||||
if (userDetails["role"] != "Travel Agent")
|
||||
_buildDrawerItem(context, Icons.assessment_outlined,
|
||||
'My Approvals', '/ApprovalList'),
|
||||
_buildDrawerItem(
|
||||
context,
|
||||
Icons.assessment_outlined,
|
||||
'My Approvals',
|
||||
'/ApprovalList',
|
||||
),
|
||||
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.5),
|
||||
Container(
|
||||
@ -206,8 +239,10 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
children: [
|
||||
Text(
|
||||
"Powered by",
|
||||
style:
|
||||
TextStyle(fontSize: 11, color: Color(0xFF212121)),
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
Image.asset(
|
||||
'assets/images/login/logoNew.jpg',
|
||||
@ -226,7 +261,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
);
|
||||
|
||||
return Drawer(
|
||||
child: ListView(padding: EdgeInsets.zero, children: [drawerContent]));
|
||||
child: ListView(padding: EdgeInsets.zero, children: [drawerContent]),
|
||||
);
|
||||
|
||||
// if (widget.isDesktop) {
|
||||
// // Sidebar for Desktop (always visible)**
|
||||
@ -244,7 +280,11 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
|
||||
/// **Reusable Drawer Item**
|
||||
Widget _buildDrawerItem(
|
||||
BuildContext context, IconData icon, String title, String route) {
|
||||
BuildContext context,
|
||||
IconData icon,
|
||||
String title,
|
||||
String route,
|
||||
) {
|
||||
String selectedRoute = GoRouterState.of(context).uri.toString();
|
||||
|
||||
// return Container(
|
||||
@ -287,10 +327,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
return Material(
|
||||
color: selectedRoute == route ? bodyColor : Colors.transparent,
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
),
|
||||
leading: Icon(icon, size: 20),
|
||||
title: Text(
|
||||
title,
|
||||
|
||||
@ -305,8 +342,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
// color: Color(0xFF475569),
|
||||
// fontFamily: "Archivo"),
|
||||
),
|
||||
// tileColor: selectedRoute == route ? Colors.blue.shade50 : null,
|
||||
|
||||
// tileColor: selectedRoute == route ? Colors.blue.shade50 : null,
|
||||
onTap: () async {
|
||||
if (route == '/') {
|
||||
// Handle logout separately
|
||||
@ -316,7 +353,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
} else {
|
||||
context.go(route);
|
||||
}
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -338,11 +376,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
child: ExpansionTile(
|
||||
tilePadding: EdgeInsets.symmetric(horizontal: 16),
|
||||
// childrenPadding: EdgeInsets.only(left: 36),
|
||||
leading: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: Color(0xFF475569),
|
||||
),
|
||||
leading: Icon(icon, size: 20, color: Color(0xFF475569)),
|
||||
title: Row(
|
||||
children: [
|
||||
// You could manually build this instead of using `leading`, but it's simpler here
|
||||
@ -378,11 +412,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 44.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.circle_rounded,
|
||||
color: Color(0xFF475569),
|
||||
size: 6,
|
||||
),
|
||||
Icon(Icons.circle_rounded, color: Color(0xFF475569), size: 6),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
@ -399,20 +429,22 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExpandableItem1(BuildContext context, IconData icon,
|
||||
String title, List<Widget> children) {
|
||||
Widget _buildExpandableItem1(
|
||||
BuildContext context,
|
||||
IconData icon,
|
||||
String title,
|
||||
List<Widget> children,
|
||||
) {
|
||||
return ExpansionTile(
|
||||
leading: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
),
|
||||
leading: Icon(icon, size: 20),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF475569),
|
||||
fontFamily: "Archivo"),
|
||||
fontFamily: "Archivo",
|
||||
),
|
||||
),
|
||||
collapsedBackgroundColor: Colors.transparent,
|
||||
shape: const Border(), // Removes top and bottom dividers
|
||||
@ -423,20 +455,20 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
}
|
||||
|
||||
Widget _buildSubDrawerItem1(
|
||||
BuildContext context, String title, String route) {
|
||||
BuildContext context,
|
||||
String title,
|
||||
String route,
|
||||
) {
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.circle_rounded,
|
||||
color: Color(0xFF475569),
|
||||
size: 8,
|
||||
),
|
||||
leading: Icon(Icons.circle_rounded, color: Color(0xFF475569), size: 8),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Color(0xFF475569),
|
||||
fontFamily: "Archivo"),
|
||||
fontFamily: "Archivo",
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
context.go(route);
|
||||
|
||||
@ -16,6 +16,7 @@ import 'package:frontend/Screens/userManagement/create_user/create_user1.dart';
|
||||
import 'package:frontend/Screens/userManagement/user_List.dart';
|
||||
import 'package:frontend/routes/organizationSetting.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
|
||||
import '../Screens/allTrips/list_all_plans.dart';
|
||||
import '../Screens/allTrips/travel_agent_list.dart';
|
||||
@ -23,6 +24,7 @@ import '../Screens/approvals/approval_list.dart';
|
||||
import '../Screens/group/group.dart';
|
||||
import '../Screens/group/groupList.dart';
|
||||
import '../Screens/myTemplates/template.dart';
|
||||
import '../Screens/myTemplates/templateForex.dart';
|
||||
import '../Screens/myTemplates/templateTest.dart';
|
||||
import '../Screens/userManagement/create_user/create_user.dart';
|
||||
import '../Screens/department/department_list.dart';
|
||||
@ -30,52 +32,57 @@ import '../Screens/costCenter/costCenter_list.dart';
|
||||
import '../Screens/dashboard/status_dashboard.dart';
|
||||
import '../Screens/hotels/hotels_list.dart';
|
||||
import '../Screens/traveller/travellerList.dart';
|
||||
import 'mainLayout.dart';
|
||||
|
||||
final GoRouter router = GoRouter(
|
||||
routes: [
|
||||
// Public routes without app bar
|
||||
GoRoute(path: '/', builder: (context, state) => LoginPage()),
|
||||
// GoRoute(
|
||||
// path: '/authredirection',
|
||||
// builder: (context, state) {
|
||||
// final code = state.uri.queryParameters['code'];
|
||||
// return MicrosoftPage(code: code);
|
||||
|
||||
// Routes that share the app bar and layout (nested routes)
|
||||
ShellRoute(
|
||||
builder: (context, state, child) {
|
||||
// Use ResponsiveBuilder here to detect isDesktop and pass to MainLayout
|
||||
return child;
|
||||
// return ResponsiveBuilder(
|
||||
// builder: (context, sizingInfo) {
|
||||
// bool isDesktop =
|
||||
// sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
//
|
||||
// return MainLayout(isDesktop: isDesktop, child: child);
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
routes: [
|
||||
GoRoute(path: '/home', builder: (context, state) => HomePage()),
|
||||
GoRoute(path: '/listAllPlan', builder: (context, state) => ListAllPlans()),
|
||||
GoRoute(
|
||||
path: '/listAllPlan',
|
||||
builder: (context, state) => ListAllPlans(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/listTravelAgentPlan',
|
||||
builder: (context, state) => TravelAgentListPlans(),
|
||||
),
|
||||
GoRoute(path: '/listPlan', builder: (context, state) => ListPlans()),
|
||||
GoRoute(path: '/createPlan', builder: (context, state) => CreatePlan()),
|
||||
GoRoute(path: '/allTrips/trips', builder: (context, state) => CreatePlan()),
|
||||
GoRoute(path: '/approver/plans', builder: (context, state) => CreatePlan()),
|
||||
GoRoute(path: '/listUser', builder: (context, state) => UserListScreen()),
|
||||
GoRoute(
|
||||
path: '/allTrips/trips',
|
||||
builder: (context, state) => CreatePlan(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/approver/plans',
|
||||
builder: (context, state) => CreatePlan(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/listUser',
|
||||
builder: (context, state) => UserListScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/CreateUserDetails',
|
||||
builder: (context, state) => CreateUserFormDetials(),
|
||||
// builder: (context, state) {
|
||||
// final userParam = state.uri.queryParameters['user'];
|
||||
//
|
||||
// final isEditProfile =
|
||||
// state.uri.queryParameters['isEditProfile'] == 'true';
|
||||
// final isViewMode = state.uri.queryParameters['isViewMode'] == 'true';
|
||||
//
|
||||
// final user = userParam != null
|
||||
// ? jsonDecode(Uri.decodeComponent(userParam))
|
||||
// : null;
|
||||
//
|
||||
// return CreateUserForm(
|
||||
// apiselectedUser: user,
|
||||
// isEditProfile: isEditProfile,
|
||||
// isViewMode: isViewMode,
|
||||
// );
|
||||
// }
|
||||
),
|
||||
GoRoute(
|
||||
path: '/Policy',
|
||||
// builder: (context, state) => Policy(),
|
||||
pageBuilder:
|
||||
(context, state) => MaterialPage(child: Policy.fromState(state)),
|
||||
),
|
||||
@ -89,24 +96,38 @@ final GoRouter router = GoRouter(
|
||||
builder: (context, state) => OrganizationSetting(),
|
||||
),
|
||||
GoRoute(path: '/group', builder: (context, state) => GroupList()),
|
||||
GoRoute(path: '/getPerdiem', builder: (context, state) => ForexDataList()),
|
||||
GoRoute(
|
||||
path: '/getPerdiem',
|
||||
builder: (context, state) => ForexDataList(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/templateList',
|
||||
builder: (context, state) => TemplatesList(),
|
||||
),
|
||||
// GoRoute(
|
||||
// path: '/template',
|
||||
// builder: (context, state) => MyHomePage(),
|
||||
// ),
|
||||
GoRoute(
|
||||
path: '/template',
|
||||
// builder: (context, state) => Template(),
|
||||
pageBuilder:
|
||||
(context, state) => MaterialPage(child: Template.fromState(state)),
|
||||
(context, state) =>
|
||||
MaterialPage(child: Template.fromState(state)),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/templateForex',
|
||||
pageBuilder:
|
||||
(context, state) =>
|
||||
MaterialPage(child: TemplateForex.fromState(state)),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/approvallist',
|
||||
builder: (context, state) => ApprovalList(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/department',
|
||||
builder: (context, state) => DepartmentList(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/costcenter',
|
||||
builder: (context, state) => CostCenterList(),
|
||||
),
|
||||
GoRoute(path: '/approvallist', builder: (context, state) => ApprovalList()),
|
||||
GoRoute(path: '/department', builder: (context, state) => DepartmentList()),
|
||||
GoRoute(path: '/costcenter', builder: (context, state) => CostCenterList()),
|
||||
GoRoute(path: '/hotels', builder: (context, state) => HotelsDataList()),
|
||||
GoRoute(
|
||||
path: '/statusdashboard',
|
||||
@ -122,4 +143,102 @@ final GoRouter router = GoRouter(
|
||||
(context, state) => MaterialPage(child: Group.fromState(state)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
// final GoRouter router = GoRouter(
|
||||
// routes: [
|
||||
// GoRoute(path: '/', builder: (context, state) => LoginPage()),
|
||||
// // GoRoute(
|
||||
// // path: '/authredirection',
|
||||
// // builder: (context, state) {
|
||||
// // final code = state.uri.queryParameters['code'];
|
||||
// // return MicrosoftPage(code: code);
|
||||
// // },
|
||||
// // ),
|
||||
// GoRoute(path: '/home', builder: (context, state) => HomePage()),
|
||||
// GoRoute(path: '/listAllPlan', builder: (context, state) => ListAllPlans()),
|
||||
// GoRoute(
|
||||
// path: '/listTravelAgentPlan',
|
||||
// builder: (context, state) => TravelAgentListPlans(),
|
||||
// ),
|
||||
// GoRoute(path: '/listPlan', builder: (context, state) => ListPlans()),
|
||||
// GoRoute(path: '/createPlan', builder: (context, state) => CreatePlan()),
|
||||
// GoRoute(path: '/allTrips/trips', builder: (context, state) => CreatePlan()),
|
||||
// GoRoute(path: '/approver/plans', builder: (context, state) => CreatePlan()),
|
||||
// GoRoute(path: '/listUser', builder: (context, state) => UserListScreen()),
|
||||
// GoRoute(
|
||||
// path: '/CreateUserDetails',
|
||||
// builder: (context, state) => CreateUserFormDetials(),
|
||||
// // builder: (context, state) {
|
||||
// // final userParam = state.uri.queryParameters['user'];
|
||||
// //
|
||||
// // final isEditProfile =
|
||||
// // state.uri.queryParameters['isEditProfile'] == 'true';
|
||||
// // final isViewMode = state.uri.queryParameters['isViewMode'] == 'true';
|
||||
// //
|
||||
// // final user = userParam != null
|
||||
// // ? jsonDecode(Uri.decodeComponent(userParam))
|
||||
// // : null;
|
||||
// //
|
||||
// // return CreateUserForm(
|
||||
// // apiselectedUser: user,
|
||||
// // isEditProfile: isEditProfile,
|
||||
// // isViewMode: isViewMode,
|
||||
// // );
|
||||
// // }
|
||||
// ),
|
||||
// GoRoute(
|
||||
// path: '/Policy',
|
||||
// // builder: (context, state) => Policy(),
|
||||
// pageBuilder:
|
||||
// (context, state) => MaterialPage(child: Policy.fromState(state)),
|
||||
// ),
|
||||
// GoRoute(path: '/PolicyList', builder: (context, state) => PolicyList()),
|
||||
// GoRoute(
|
||||
// path: '/OrganizationSetup',
|
||||
// builder: (context, state) => OrgSetUp(),
|
||||
// ),
|
||||
// GoRoute(
|
||||
// path: '/OrganizationSettings',
|
||||
// builder: (context, state) => OrganizationSetting(),
|
||||
// ),
|
||||
// GoRoute(path: '/group', builder: (context, state) => GroupList()),
|
||||
// GoRoute(path: '/getPerdiem', builder: (context, state) => ForexDataList()),
|
||||
// GoRoute(
|
||||
// path: '/templateList',
|
||||
// builder: (context, state) => TemplatesList(),
|
||||
// ),
|
||||
// // GoRoute(
|
||||
// // path: '/template',
|
||||
// // builder: (context, state) => MyHomePage(),
|
||||
// // ),
|
||||
// GoRoute(
|
||||
// path: '/template',
|
||||
// // builder: (context, state) => Template(),
|
||||
// pageBuilder:
|
||||
// (context, state) => MaterialPage(child: Template.fromState(state)),
|
||||
// ),
|
||||
// GoRoute(
|
||||
// path: '/templateForex',
|
||||
// pageBuilder:
|
||||
// (context, state) =>
|
||||
// MaterialPage(child: TemplateForex.fromState(state)),
|
||||
// ),
|
||||
// GoRoute(path: '/approvallist', builder: (context, state) => ApprovalList()),
|
||||
// GoRoute(path: '/department', builder: (context, state) => DepartmentList()),
|
||||
// GoRoute(path: '/costcenter', builder: (context, state) => CostCenterList()),
|
||||
// GoRoute(path: '/hotels', builder: (context, state) => HotelsDataList()),
|
||||
// GoRoute(
|
||||
// path: '/statusdashboard',
|
||||
// builder: (context, state) => StatusDashboard(),
|
||||
// ),
|
||||
// GoRoute(path: '/traveller', builder: (context, state) => TravellerList()),
|
||||
// GoRoute(
|
||||
// path: '/CreateGroup',
|
||||
// pageBuilder:
|
||||
// (context, state) => MaterialPage(child: Group.fromState(state)),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
|
||||
33
lib/routes/mainLayout.dart
Normal file
33
lib/routes/mainLayout.dart
Normal file
@ -0,0 +1,33 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
|
||||
import 'custom_appBar.dart';
|
||||
import 'custom_drawer.dart';
|
||||
|
||||
class MainLayout extends StatelessWidget {
|
||||
final Widget child;
|
||||
final bool isDesktop;
|
||||
|
||||
const MainLayout({required this.child, required this.isDesktop, Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFf5f5f5),
|
||||
appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
drawer: isDesktop ? null : CustomDrawer(isDesktop: false),
|
||||
body: Padding(
|
||||
padding:
|
||||
isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.1,
|
||||
vertical: 0,
|
||||
)
|
||||
: EdgeInsets.zero,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
|
||||
import '../services/apiService.dart';
|
||||
import 'custom_appBar.dart';
|
||||
import 'custom_drawer.dart';
|
||||
|
||||
@ -15,6 +16,8 @@ class OrganizationSetting extends StatefulWidget {
|
||||
}
|
||||
|
||||
class OrganizationSettingState extends State<OrganizationSetting> {
|
||||
final ApiService apiService = ApiService();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(
|
||||
@ -84,7 +87,7 @@ class OrganizationSettingState extends State<OrganizationSetting> {
|
||||
'description': 'Create and Edit Perdiem Amount',
|
||||
},
|
||||
{
|
||||
'value': '/department',
|
||||
'value': '/forexTexmplate',
|
||||
'icon': Icons.group_add_outlined,
|
||||
'label': 'Forex Template',
|
||||
'description': 'Create and Edit Template',
|
||||
@ -244,9 +247,21 @@ class OrganizationSettingState extends State<OrganizationSetting> {
|
||||
child: Card(
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
if (item['value'] as String ==
|
||||
"/forexTexmplate") {
|
||||
final data =
|
||||
await apiService.getForexTemplate();
|
||||
print("ForexId -- $data");
|
||||
|
||||
context.go(
|
||||
'/templateForex',
|
||||
extra: {'templateData': data},
|
||||
);
|
||||
} else {
|
||||
final route = item['value'] as String;
|
||||
context.go(route);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
|
||||
@ -5,11 +5,32 @@ import 'package:frontend/utils/auth_utils.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
import 'package:universal_html/js.dart';
|
||||
import '../../config/apiUrl.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ApiService {
|
||||
Future<void> getOrganizationData() async {
|
||||
try {
|
||||
print("getUpdatedServices");
|
||||
final result = await fetchOrganization();
|
||||
print("UUPdatedServices - $result");
|
||||
|
||||
// ✅ Save to local storage
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final jsonString = jsonEncode(result);
|
||||
await prefs.setString('org_data', jsonString);
|
||||
print("✅ Organization data saved to SharedPreferences.");
|
||||
|
||||
print("selectedOrg - $result");
|
||||
} catch (e) {
|
||||
print('Error fetching updatedServices list: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> fetchCountryList() async {
|
||||
final String apiUrldata = '$apiUrl/api/getcountryMaster';
|
||||
final token = await getToken();
|
||||
@ -33,7 +54,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
return data['data'];
|
||||
@ -68,7 +90,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
return data['data'];
|
||||
@ -136,7 +159,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
List<dynamic> plansJson = data['data']; // 'data' is a Map, not a List
|
||||
@ -190,7 +214,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
List<dynamic> plansJson = data['data']; // 'data' is a Map, not a List
|
||||
@ -239,7 +264,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> plansJson =
|
||||
@ -277,7 +303,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
return data['data'];
|
||||
} catch (e) {
|
||||
@ -313,7 +340,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
return data['data'];
|
||||
} catch (e) {
|
||||
@ -349,7 +377,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
return data['data'];
|
||||
} catch (e) {
|
||||
@ -385,7 +414,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
return data['data'];
|
||||
} catch (e) {
|
||||
@ -419,7 +449,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> plansJson =
|
||||
@ -460,7 +491,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
// Make sure each item is a Map<String, dynamic>
|
||||
@ -527,33 +559,47 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> viewPlan(BuildContext context, String planId,
|
||||
{bool isViewMode = false, bool isMyTrips = false}) async {
|
||||
static Future<void> viewPlan(
|
||||
BuildContext context,
|
||||
String planId, {
|
||||
bool isViewMode = false,
|
||||
bool isMyTrips = false,
|
||||
}) async {
|
||||
try {
|
||||
Map<String, dynamic> planData = await getViewPlanEdit(planId);
|
||||
print("ViewAAA - $planData");
|
||||
|
||||
context.go(isMyTrips ? '/createPlan' : '/allTrips/trips',
|
||||
extra: {'planData': planData, 'isViewMode': isViewMode});
|
||||
context.go(
|
||||
isMyTrips ? '/createPlan' : '/allTrips/trips',
|
||||
extra: {'planData': planData, 'isViewMode': isViewMode},
|
||||
);
|
||||
} catch (e) {
|
||||
print("Error fetching plan: $e");
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> viewPlanForApprover(BuildContext context, String planId,
|
||||
String? approverId, String? delegaterId,
|
||||
{bool isViewMode = false, bool isApprover = true}) async {
|
||||
static Future<void> viewPlanForApprover(
|
||||
BuildContext context,
|
||||
String planId,
|
||||
String? approverId,
|
||||
String? delegaterId, {
|
||||
bool isViewMode = false,
|
||||
bool isApprover = true,
|
||||
}) async {
|
||||
try {
|
||||
Map<String, dynamic> planData = await getViewPlanEdit(planId);
|
||||
print("ViewAAA - $planData");
|
||||
|
||||
context.replace('/approver/plans', extra: {
|
||||
context.replace(
|
||||
'/approver/plans',
|
||||
extra: {
|
||||
'planData': planData,
|
||||
'approverId': approverId,
|
||||
'delegaterId': delegaterId,
|
||||
'isViewMode': isViewMode,
|
||||
'isApprover': isApprover,
|
||||
});
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print("Error fetching plan: $e");
|
||||
}
|
||||
@ -589,7 +635,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
// Make sure each item is a Map<String, dynamic>
|
||||
@ -635,7 +682,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
return data['data'];
|
||||
@ -671,7 +719,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
return data['data'];
|
||||
@ -709,11 +758,12 @@ class ApiService {
|
||||
// Create a blob from the response body
|
||||
final blob = html.Blob([response.bodyBytes]);
|
||||
|
||||
// Generate a download URL for the blob
|
||||
// Generate a download URL for the blob
|
||||
final url = html.Url.createObjectUrlFromBlob(blob);
|
||||
|
||||
// Create a link element to trigger the download
|
||||
final anchor = html.AnchorElement(href: url)
|
||||
final anchor =
|
||||
html.AnchorElement(href: url)
|
||||
..setAttribute('download', 'trip_plan_$planId.pdf')
|
||||
..click();
|
||||
|
||||
@ -772,11 +822,12 @@ class ApiService {
|
||||
// Create a blob from the response body
|
||||
final blob = html.Blob([response.bodyBytes]);
|
||||
|
||||
// Generate a download URL for the blob
|
||||
// Generate a download URL for the blob
|
||||
final url = html.Url.createObjectUrlFromBlob(blob);
|
||||
|
||||
// Create a link element to trigger the download
|
||||
final anchor = html.AnchorElement(href: url)
|
||||
final anchor =
|
||||
html.AnchorElement(href: url)
|
||||
..setAttribute('download', 'Forex_$forexId.pdf')
|
||||
..click();
|
||||
|
||||
@ -835,7 +886,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
print('Single USer 1');
|
||||
|
||||
@ -880,7 +932,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
final List<dynamic> forexList = data['data'];
|
||||
@ -925,7 +978,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
@ -984,7 +1038,62 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
return Map<String, dynamic>.from(data['data']);
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
} else {
|
||||
throw Exception('Failed to load department details');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getForexTemplate() async {
|
||||
final String apiUrldata =
|
||||
'$apiUrl/api/getForexTemplate?template_name=forex';
|
||||
|
||||
final token = await getToken();
|
||||
|
||||
if (token == null) {
|
||||
throw Exception('Token not found. Please log in.');
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(apiUrldata),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
final data = json.decode(response.body);
|
||||
// print('findout the result');
|
||||
// print(data.runtimeType);
|
||||
print(data);
|
||||
|
||||
// if (!data.containsKey('data') || data['data'] is! List) {
|
||||
// throw Exception(
|
||||
// "Invalid response format: 'data' field is missing or not a List");
|
||||
// }
|
||||
//
|
||||
// final List<Map<String, dynamic>> listData =
|
||||
// List<Map<String, dynamic>>.from(data['data']);
|
||||
//
|
||||
// if (listData.isEmpty) {
|
||||
// throw Exception("No department found with ID $id");
|
||||
// }
|
||||
//
|
||||
// return listData[0];
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
|
||||
return Map<String, dynamic>.from(data['data']);
|
||||
@ -997,7 +1106,9 @@ class ApiService {
|
||||
}
|
||||
|
||||
Future<bool> showCancelConfirmationDialog(
|
||||
BuildContext context, Color? layoutColor) async {
|
||||
BuildContext context,
|
||||
Color? layoutColor,
|
||||
) async {
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
@ -1006,12 +1117,16 @@ class ApiService {
|
||||
title: Text(
|
||||
'Cancel Confirmation',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 18, fontWeight: FontWeight.w500),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
'Do you want to cancel?',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14.5, fontWeight: FontWeight.w500),
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
@ -1021,10 +1136,11 @@ class ApiService {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(
|
||||
color: layoutColor ?? Colors.grey, width: 2),
|
||||
color: layoutColor ?? Colors.grey,
|
||||
width: 2,
|
||||
),
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
@ -1032,7 +1148,8 @@ class ApiService {
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
)),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: layoutColor, // Keep original color
|
||||
@ -1043,16 +1160,17 @@ class ApiService {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(
|
||||
color: layoutColor ?? Colors.grey, width: 1),
|
||||
color: layoutColor ?? Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
onPressed: () => Navigator.of(context)
|
||||
.pop(true), // Disable when in view mode
|
||||
child: Text(
|
||||
"OK",
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
onPressed:
|
||||
() => Navigator.of(
|
||||
context,
|
||||
).pop(true), // Disable when in view mode
|
||||
child: Text("OK", style: GoogleFonts.poppins(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -1087,7 +1205,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
@ -1132,7 +1251,8 @@ class ApiService {
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
@ -1174,7 +1294,8 @@ class ApiService {
|
||||
print(data);
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
"Invalid response format: 'data' field is missing or not a Map",
|
||||
);
|
||||
}
|
||||
print('Single USer 1');
|
||||
|
||||
@ -1194,7 +1315,6 @@ class ApiService {
|
||||
Future<Map<String, dynamic>> getTravellerDetailsFind(int id) async {
|
||||
final String apiUrldata = '$apiUrl/api/travellers/find?traveller_id=$id';
|
||||
|
||||
|
||||
//c
|
||||
final token = await getToken();
|
||||
|
||||
@ -1215,7 +1335,9 @@ class ApiService {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
throw Exception("Invalid response format: 'data' field is missing or not a List");
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List",
|
||||
);
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
@ -1233,5 +1355,4 @@ class ApiService {
|
||||
throw Exception('Failed to load Hotel details');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user