authentication
This commit is contained in:
parent
08f80a8afa
commit
6bb37994de
BIN
assets/images/IconsImg/download.png
Normal file
BIN
assets/images/IconsImg/download.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 741 B |
BIN
assets/images/IconsImg/upload.png
Normal file
BIN
assets/images/IconsImg/upload.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 729 B |
@ -50,20 +50,37 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getToken();
|
||||
_checkAuthAndLoadData();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// // If token exists, load the dashboard data
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
//
|
||||
// // futurePlans.then((plans) {
|
||||
// // setState(() {
|
||||
// // allPlans = plans;
|
||||
// // filteredPlans = plans;
|
||||
// // });
|
||||
// // });
|
||||
// });
|
||||
// // futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
} else {
|
||||
getToken();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
|
||||
// futurePlans.then((plans) {
|
||||
// setState(() {
|
||||
// allPlans = plans;
|
||||
// filteredPlans = plans;
|
||||
// });
|
||||
// });
|
||||
});
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
}
|
||||
|
||||
void filterPlans(String query) {
|
||||
|
||||
@ -48,23 +48,39 @@ class _TravelAgentListPlansState extends State<TravelAgentListPlans> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getToken();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
|
||||
// futurePlans.then((plans) {
|
||||
// setState(() {
|
||||
// allPlans = plans;
|
||||
// filteredPlans = plans;
|
||||
// });
|
||||
// });
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// getToken();
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
//
|
||||
// // futurePlans.then((plans) {
|
||||
// // setState(() {
|
||||
// // allPlans = plans;
|
||||
// // filteredPlans = plans;
|
||||
// // });
|
||||
// // });
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
getToken();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
void filterPlans(String query) {
|
||||
print("allPlans before filtering: $allPlans");
|
||||
final lowerQuery = query.toLowerCase();
|
||||
|
||||
@ -46,16 +46,32 @@ class _ApprovalListState extends State<ApprovalList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getToken();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// getToken();
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
getToken();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
@ -776,9 +792,9 @@ class _ApprovalListState extends State<ApprovalList> {
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
plan.userName.isNotEmpty
|
||||
? plan.userName
|
||||
: plan.travellerName,
|
||||
plan.userName.isNotEmpty
|
||||
? plan.userName
|
||||
: plan.travellerName,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
|
||||
@ -135,16 +135,10 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
timeInSecForIosWeb: 2,
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0,
|
||||
fontSize: 18.0,
|
||||
webBgColor: "linear-gradient(to right, #28a745, #28a745)",
|
||||
);
|
||||
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Login Successful"),
|
||||
// backgroundColor: Colors.green, // Set background to green
|
||||
// ),
|
||||
// );
|
||||
|
||||
if (userRole == "Travel Agent") {
|
||||
context.go('/listTravelAgentPlan');
|
||||
} else if (userRole == "Org Admin" || userRole == "Travel Admin") {
|
||||
@ -225,12 +219,6 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
_showOtpResetFields = true;
|
||||
// _clearAllFields();
|
||||
});
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("OTP sent to your email"),
|
||||
// backgroundColor: Colors.green,
|
||||
// ),
|
||||
// );
|
||||
|
||||
Fluttertoast.showToast(
|
||||
msg: "OTP sent to your email",
|
||||
@ -240,18 +228,10 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0,
|
||||
webBgColor: "linear-gradient(to right, #28a745, #28a745)",
|
||||
);
|
||||
} else {
|
||||
print(response);
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text(
|
||||
// "${jsonDecode(response.body)['messages']['error']}",
|
||||
// ),
|
||||
//
|
||||
// backgroundColor: Colors.red,
|
||||
// ),
|
||||
// );
|
||||
|
||||
Fluttertoast.showToast(
|
||||
msg: "${jsonDecode(response.body)['messages']['error']}",
|
||||
@ -304,12 +284,6 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
_showOtpResetFields = false;
|
||||
_clearAllFields();
|
||||
});
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Password reset successfully"),
|
||||
// backgroundColor: Colors.green,
|
||||
// ),
|
||||
// );
|
||||
|
||||
Fluttertoast.showToast(
|
||||
msg: "Password reset successfully",
|
||||
@ -319,6 +293,7 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0,
|
||||
webBgColor: "linear-gradient(to right, #28a745, #28a745)",
|
||||
);
|
||||
} else {
|
||||
print('23');
|
||||
@ -521,6 +496,7 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
fontSize: widget.isDesktop ? 20 : 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.green,
|
||||
|
||||
// color: Color(0xFF212121),
|
||||
),
|
||||
),
|
||||
|
||||
@ -28,7 +28,8 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
GlobalKey<CostCenterListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureCostCenter;
|
||||
Future<List<dynamic>>? futureCostCenter;
|
||||
// late Future<List<dynamic>> futureCostCenter;
|
||||
|
||||
late Map<String, dynamic> depSingleData;
|
||||
String? selectedCostCenterId;
|
||||
@ -47,21 +48,50 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureCostCenter = fetchGetCostCenter();
|
||||
|
||||
futureCostCenter.then((object) {
|
||||
setState(() {
|
||||
allCostCenter = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futureCostCenter = fetchGetCostCenter();
|
||||
//
|
||||
// futureCostCenter.then((object) {
|
||||
// setState(() {
|
||||
// allCostCenter = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureCostCenter = fetchGetCostCenter();
|
||||
|
||||
futureCostCenter?.then((object) {
|
||||
setState(() {
|
||||
allCostCenter = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
@ -89,7 +119,7 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
|
||||
futureCostCenter = fetchGetCostCenter();
|
||||
|
||||
return futureCostCenter.then((object) {
|
||||
return futureCostCenter!.then((object) {
|
||||
print("Calling Refresh Data $object");
|
||||
setState(() {
|
||||
allCostCenter = object;
|
||||
@ -406,6 +436,10 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureCostCenter,
|
||||
builder: (context, snapshot) {
|
||||
if (futureCostCenter == null) {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frontend/routes/custom_router.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@ -16,7 +20,6 @@ import '../../utils/auth_utils.dart';
|
||||
import '../../utils/pagination.dart';
|
||||
|
||||
class StatusDashboard extends StatefulWidget {
|
||||
|
||||
const StatusDashboard({super.key});
|
||||
|
||||
@override
|
||||
@ -24,15 +27,101 @@ class StatusDashboard extends StatefulWidget {
|
||||
}
|
||||
|
||||
class StatusDashboardState extends State<StatusDashboard> {
|
||||
|
||||
Map<String, dynamic>? apiData;
|
||||
String? organizationId;
|
||||
late bool _dialogShown = false;
|
||||
late StreamSubscription<html.PopStateEvent> _popStateListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadDashboardData();
|
||||
_checkAuthAndLoadData();
|
||||
|
||||
checkbackbutton();
|
||||
|
||||
// loadDashboardData();
|
||||
}
|
||||
|
||||
void checkbackbutton() async {
|
||||
// Push a dummy state so back button triggers popstate instead of navigating
|
||||
html.window.history.pushState(null, 'home', html.window.location.href);
|
||||
|
||||
_popStateListener = html.window.onPopState.listen((event) {
|
||||
if (!_dialogShown && mounted) {
|
||||
_showBackConfirmationDialog();
|
||||
}
|
||||
|
||||
// Re-push to prevent leaving
|
||||
html.window.history.pushState(null, 'home', html.window.location.href);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_popStateListener.cancel(); // ✅ Remove the browser popstate listener
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showBackConfirmationDialog() {
|
||||
if (!mounted) return;
|
||||
|
||||
_dialogShown = true;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: Text("Confirm"),
|
||||
content: Text("Do you want to logout?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Close dialog
|
||||
_dialogShown = false;
|
||||
},
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context); // Close dialog
|
||||
_dialogShown = false;
|
||||
await _logoutAndRedirect(context);
|
||||
},
|
||||
child: Text("Logout"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _logoutAndRedirect(BuildContext context) async {
|
||||
print("logue 0");
|
||||
|
||||
// Example: clear session or shared preferences
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.clear();
|
||||
|
||||
context.go("/");
|
||||
|
||||
print("logue 1");
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
checkbackbutton();
|
||||
});
|
||||
// If token exists, load the dashboard data
|
||||
loadDashboardData();
|
||||
}
|
||||
|
||||
Future<void> loadDashboardData() async {
|
||||
@ -66,13 +155,11 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> fetchStatusDashboard() async {
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> fetchStatusDashboard() async {
|
||||
organizationId = await getOrgId();
|
||||
|
||||
final String apiUrlData = '$apiUrl/api/plans/statusDashboard?org_id=$organizationId';
|
||||
final String apiUrlData =
|
||||
'$apiUrl/api/plans/statusDashboard?org_id=$organizationId';
|
||||
final String? token = await getToken();
|
||||
|
||||
print("Fetch StatusDashboard -- 2KN Here : $token");
|
||||
@ -132,17 +219,18 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final typeBasedCount = List<Map<String, dynamic>>.from(
|
||||
(apiData?['data']?['typeBasedCount']) ?? []);
|
||||
(apiData?['data']?['typeBasedCount']) ?? [],
|
||||
);
|
||||
|
||||
print("apiData - => $apiData");
|
||||
print("typeBasedCount => $typeBasedCount");
|
||||
|
||||
final statusBasedCount = List<Map<String, dynamic>>.from(
|
||||
(apiData?['data']?['statusBasedCount']) ?? []);
|
||||
(apiData?['data']?['statusBasedCount']) ?? [],
|
||||
);
|
||||
print("statusBasedCount - => $statusBasedCount");
|
||||
// 👇 Local function to create the card widget
|
||||
Widget buildInfoCard(String title, int count, double width) {
|
||||
@ -159,14 +247,24 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 32, color: (title == 'Domestic' || title == 'International') ? Colors.green : Colors.black54), // 👈 Add Icon here
|
||||
Icon(
|
||||
icon,
|
||||
size: 32,
|
||||
color:
|
||||
(title == 'Domestic' || title == 'International')
|
||||
? Colors.green
|
||||
: Colors.black54,
|
||||
), // 👈 Add Icon here
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: (title == 'Domestic' || title == 'International') ? 16 : 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize:
|
||||
(title == 'Domestic' || title == 'International')
|
||||
? 16
|
||||
: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@ -182,95 +280,144 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
void _handleBackButton() {
|
||||
final location = GoRouterState.of(context).uri.toString();
|
||||
|
||||
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: 10, // 5% of screen height as vertical padding
|
||||
print("location - $location");
|
||||
if (location.contains('/StatusDashboard')) {
|
||||
// Do nothing or show "Press again to exit" toast
|
||||
print("Blocked back on dashboard");
|
||||
} else {
|
||||
print("dashboard ..");
|
||||
}
|
||||
}
|
||||
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return PopScope(
|
||||
canPop: false, // Allow back navigation only if not login screen
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
_handleBackButton(); // Show exit confirmation dialog
|
||||
},
|
||||
child: 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: 10, // 5% of screen height as vertical padding
|
||||
)
|
||||
: EdgeInsets.all(0),
|
||||
child : LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: IntrinsicHeight( // Only needed if child layout depends on height
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isDesktop ? Colors.white : const Color(0xFFFCFCFC),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: typeBasedCount.map((item) {
|
||||
double cardWidth = isDesktop
|
||||
? (MediaQuery.of(context).size.width * 0.75 - 10) / 2 // 80% width padding adjusted
|
||||
: MediaQuery.of(context).size.width - 24; // full width with padding
|
||||
: EdgeInsets.all(0),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: IntrinsicHeight(
|
||||
// Only needed if child layout depends on height
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
isDesktop
|
||||
? Colors.white
|
||||
: const Color(0xFFFCFCFC),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children:
|
||||
typeBasedCount.map((item) {
|
||||
double cardWidth =
|
||||
isDesktop
|
||||
? (MediaQuery.of(
|
||||
context,
|
||||
).size.width *
|
||||
0.75 -
|
||||
10) /
|
||||
2 // 80% width padding adjusted
|
||||
: MediaQuery.of(
|
||||
context,
|
||||
).size.width -
|
||||
24; // full width with padding
|
||||
|
||||
return SizedBox(
|
||||
width: cardWidth,
|
||||
child: buildInfoCard(item['value'], item['count'], cardWidth),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: statusBasedCount.map((item) {
|
||||
double cardWidth = isDesktop
|
||||
? (MediaQuery.of(context).size.width * 0.90 - 50) / 6 // desktop layout: 6 cards per row
|
||||
: MediaQuery.of(context).size.width - 24; // mobile: full width
|
||||
|
||||
return SizedBox(
|
||||
width: cardWidth,
|
||||
child: buildInfoCard(item['value'], item['count'], cardWidth),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
),
|
||||
);
|
||||
});
|
||||
return SizedBox(
|
||||
width: cardWidth,
|
||||
child: buildInfoCard(
|
||||
item['value'],
|
||||
item['count'],
|
||||
cardWidth,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children:
|
||||
statusBasedCount.map((item) {
|
||||
double cardWidth =
|
||||
isDesktop
|
||||
? (MediaQuery.of(
|
||||
context,
|
||||
).size.width *
|
||||
0.90 -
|
||||
50) /
|
||||
6 // desktop layout: 6 cards per row
|
||||
: MediaQuery.of(
|
||||
context,
|
||||
).size.width -
|
||||
24; // mobile: full width
|
||||
|
||||
return SizedBox(
|
||||
width: cardWidth,
|
||||
child: buildInfoCard(
|
||||
item['value'],
|
||||
item['count'],
|
||||
cardWidth,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,8 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
GlobalKey<DepartmentListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureDepartment;
|
||||
// late Future<List<dynamic>> futureDepartment;
|
||||
Future<List<dynamic>>? futureDepartment;
|
||||
|
||||
late Map<String, dynamic> depSingleData;
|
||||
String? selectedDepartmentId;
|
||||
@ -47,21 +48,50 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureDepartment = fetchGetDepartment();
|
||||
|
||||
futureDepartment.then((object) {
|
||||
setState(() {
|
||||
allDepartment = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futureDepartment = fetchGetDepartment();
|
||||
//
|
||||
// futureDepartment.then((object) {
|
||||
// setState(() {
|
||||
// allDepartment = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureDepartment = fetchGetDepartment();
|
||||
|
||||
futureDepartment?.then((object) {
|
||||
setState(() {
|
||||
allDepartment = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
@ -89,7 +119,7 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
|
||||
futureDepartment = fetchGetDepartment();
|
||||
|
||||
return futureDepartment.then((object) {
|
||||
return futureDepartment!.then((object) {
|
||||
print("Calling Refresh Data $object");
|
||||
setState(() {
|
||||
allDepartment = object;
|
||||
@ -405,6 +435,10 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureDepartment,
|
||||
builder: (context, snapshot) {
|
||||
if (futureDepartment == null) {
|
||||
CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -14,7 +14,7 @@ import '../../widgets/custom_text_forex.dart';
|
||||
import 'forex_list.dart';
|
||||
|
||||
class ForexData extends StatefulWidget {
|
||||
final Future<List<dynamic>> Function() fetchGetForex;
|
||||
final Future<List<dynamic>?> Function() fetchGetForex;
|
||||
final bool isDesktop;
|
||||
final Color? layoutColor;
|
||||
|
||||
|
||||
@ -29,7 +29,8 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
GlobalKey<ForexDataListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureForex;
|
||||
// late Future<List<dynamic>> futureForex;
|
||||
Future<List<dynamic>>? futureForex;
|
||||
|
||||
late Map<String, dynamic> userSingleData;
|
||||
List<dynamic>? apiCountryData;
|
||||
@ -49,28 +50,74 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureForex = fetchGetForex();
|
||||
|
||||
futureForex.then((users) {
|
||||
setState(() {
|
||||
allForex = users;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futureForex = fetchGetForex();
|
||||
//
|
||||
// futureForex.then((users) {
|
||||
// setState(() {
|
||||
// allForex = users;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
Future<List<dynamic>> refreshData() {
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureForex = fetchGetForex();
|
||||
|
||||
futureForex?.then((users) {
|
||||
setState(() {
|
||||
allForex = users;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
// Future<List<dynamic>?> refreshData() {
|
||||
// print("Calling Refresh Data");
|
||||
//
|
||||
// // futureForex = fetchGetForex();
|
||||
// futureForex = fetchGetForex() ?? Future.value([]);
|
||||
//
|
||||
// return futureForex.then((users) {
|
||||
// setState(() {
|
||||
// allForex = users;
|
||||
// filteredForex = users;
|
||||
// searchController.text = "";
|
||||
// });
|
||||
// return users;
|
||||
// });
|
||||
// }
|
||||
|
||||
Future<List<dynamic>?> refreshData() {
|
||||
print("Calling Refresh Data");
|
||||
|
||||
futureForex = fetchGetForex();
|
||||
|
||||
return futureForex.then((users) {
|
||||
return futureForex!.then((users) {
|
||||
setState(() {
|
||||
allForex = users;
|
||||
filteredForex = users;
|
||||
@ -557,6 +604,9 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureForex,
|
||||
builder: (context, snapshot) {
|
||||
if (futureForex == null) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
@ -748,9 +798,10 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
color: forex['is_active'] == "1"
|
||||
? Colors.green
|
||||
: Colors.grey,
|
||||
color:
|
||||
forex['is_active'] == "1"
|
||||
? Colors.green
|
||||
: Colors.grey,
|
||||
),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@ -23,7 +23,9 @@ class GroupList extends StatefulWidget {
|
||||
class _GroupListState extends State<GroupList> {
|
||||
final ApiService apiService = ApiService();
|
||||
|
||||
late Future<List<dynamic>> futureGroups;
|
||||
// late Future<List<dynamic>> futureGroups;
|
||||
|
||||
Future<List<dynamic>>? futureGroups;
|
||||
|
||||
late Map<String, dynamic> groupSingleData;
|
||||
List<dynamic>? apiCountryData;
|
||||
@ -45,21 +47,50 @@ class _GroupListState extends State<GroupList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureGroups = fetchGroups();
|
||||
_checkAuthAndLoadData();
|
||||
// futureGroups = fetchGroups();
|
||||
//
|
||||
// futureGroups.then((object) {
|
||||
// setState(() {
|
||||
// allGroups = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// fetchGroups();
|
||||
// loadAllGroups();
|
||||
// });
|
||||
|
||||
futureGroups.then((object) {
|
||||
setState(() {
|
||||
allGroups = object;
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureGroups = fetchGroups();
|
||||
|
||||
futureGroups?.then((object) {
|
||||
setState(() {
|
||||
allGroups = object;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
fetchGroups();
|
||||
loadAllGroups();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -420,9 +451,14 @@ class _GroupListState extends State<GroupList> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureGroups,
|
||||
builder: (context, snapshot) {
|
||||
if (futureGroups == null) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -29,7 +29,8 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
GlobalKey<HotelsDataListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureHotels;
|
||||
Future<List<dynamic>>? futureHotels;
|
||||
// late Future<List<dynamic>> futureHotels;
|
||||
|
||||
late Map<String, dynamic> userSingleData;
|
||||
List<dynamic>? apiCountryData;
|
||||
@ -49,28 +50,58 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureHotels = fetchGetHotels();
|
||||
|
||||
futureHotels.then((objects) {
|
||||
setState(() {
|
||||
allHotels = objects;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futureHotels = fetchGetHotels();
|
||||
//
|
||||
// futureHotels.then((objects) {
|
||||
// setState(() {
|
||||
// allHotels = objects;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureHotels = fetchGetHotels();
|
||||
|
||||
futureHotels?.then((objects) {
|
||||
setState(() {
|
||||
allHotels = objects;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> refreshData() {
|
||||
print("Calling Refresh Data");
|
||||
|
||||
futureHotels = fetchGetHotels();
|
||||
|
||||
return futureHotels.then((objects) {
|
||||
return futureHotels!.then((objects) {
|
||||
setState(() {
|
||||
allHotels = objects;
|
||||
filteredHotels = objects;
|
||||
@ -454,6 +485,10 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureHotels,
|
||||
builder: (context, snapshot) {
|
||||
if (futureHotels == null) {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -102,14 +102,39 @@ class TemplateState extends State<Template> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
//
|
||||
// for (var field in dataHeader) {
|
||||
// controllers[field] = TextEditingController();
|
||||
// }
|
||||
//
|
||||
// updateData();
|
||||
// loadinitializeData();
|
||||
// loadInitialData();
|
||||
}
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -108,14 +108,39 @@ class TemplateForexState extends State<TemplateForex> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
//
|
||||
// for (var field in dataHeader) {
|
||||
// controllers[field] = TextEditingController();
|
||||
// }
|
||||
//
|
||||
// updateData();
|
||||
// loadinitializeData();
|
||||
// loadInitialData();
|
||||
}
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -53,13 +53,29 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadAllServices();
|
||||
// getOrganizationData();
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
// });
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadAllServices();
|
||||
getOrganizationData();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
});
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
loadAllServices();
|
||||
getOrganizationData();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
|
||||
@ -48,6 +48,20 @@ class _CreatePlansState extends State<CreatePlan> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
// loadInitialData();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:frontend/data/models/plan.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
@ -12,6 +15,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../routes/custom_appBar.dart';
|
||||
import '../../routes/custom_drawer.dart';
|
||||
import '../../routes/custom_router.dart';
|
||||
import '../../services/apiService.dart';
|
||||
import '../../utils/auth_utils.dart';
|
||||
import '../../utils/pagination.dart';
|
||||
@ -35,6 +39,7 @@ class _ListPlansState extends State<ListPlans> {
|
||||
|
||||
String? userId;
|
||||
String? orgId;
|
||||
String? roleUser;
|
||||
String? token;
|
||||
String? TripPlanAction;
|
||||
|
||||
@ -44,37 +49,115 @@ class _ListPlansState extends State<ListPlans> {
|
||||
List<Plan> allPlans = [];
|
||||
List<Plan> filteredPlans = [];
|
||||
TextEditingController searchController = TextEditingController();
|
||||
String? location;
|
||||
|
||||
late bool _dialogShown = false;
|
||||
late StreamSubscription<html.PopStateEvent> _popStateListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
//
|
||||
// futurePlans.then((plans) {
|
||||
// setState(() {
|
||||
// allPlans = plans;
|
||||
// filteredPlans = plans;
|
||||
// });
|
||||
// });
|
||||
_checkAuthAndLoadData();
|
||||
checkbackbutton();
|
||||
|
||||
getToken();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
// getToken();
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
void checkbackbutton() async {
|
||||
roleUser = await getRoleUser();
|
||||
print(roleUser);
|
||||
if (roleUser == "User") {
|
||||
print("user");
|
||||
// Push a dummy state so back button triggers popstate instead of navigating
|
||||
html.window.history.pushState(null, '', html.window.location.href);
|
||||
|
||||
// futurePlans.then((plans) {
|
||||
// setState(() {
|
||||
// allPlans = plans;
|
||||
// filteredPlans = plans;
|
||||
// });
|
||||
// });
|
||||
});
|
||||
_popStateListener = html.window.onPopState.listen((event) {
|
||||
if (!_dialogShown && mounted) {
|
||||
_showBackConfirmationDialog();
|
||||
}
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
// Re-push to prevent leaving
|
||||
html.window.history.pushState(null, '', html.window.location.href);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_popStateListener.cancel(); // ✅ Remove the browser popstate listener
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showBackConfirmationDialog() {
|
||||
if (!mounted) return;
|
||||
|
||||
_dialogShown = true;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: Text("Confirm"),
|
||||
content: Text("Do you want to logout?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Close dialog
|
||||
_dialogShown = false;
|
||||
},
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context); // Close dialog
|
||||
_dialogShown = false;
|
||||
await _logoutAndRedirect(context);
|
||||
},
|
||||
child: Text("Logout"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _logoutAndRedirect(BuildContext context) async {
|
||||
print("logue 0");
|
||||
|
||||
// Example: clear session or shared preferences
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.clear();
|
||||
|
||||
context.go("/");
|
||||
|
||||
print("logue 1");
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
} else {
|
||||
if (roleUser == "User") {
|
||||
print("user");
|
||||
|
||||
// ✅ After login is successful and navigation completes:
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
checkbackbutton();
|
||||
});
|
||||
}
|
||||
getToken();
|
||||
initializeData();
|
||||
loadInitialData();
|
||||
}
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
@ -135,6 +218,7 @@ class _ListPlansState extends State<ListPlans> {
|
||||
token = await getToken();
|
||||
userId = await getUserId();
|
||||
orgId = await getOrgId();
|
||||
roleUser = await getRoleUser();
|
||||
TripPlanAction = await getTripPlanAction();
|
||||
|
||||
if (token == null || userId == null) {
|
||||
@ -325,35 +409,54 @@ class _ListPlansState extends State<ListPlans> {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleBackButton() {
|
||||
// final location = GoRouterState.of(context).uri.toString();
|
||||
|
||||
print("location - $location");
|
||||
if (location!.contains('/listPlan')) {
|
||||
// Do nothing or show "Press again to exit" toast
|
||||
print("Blocked back on /listPlan");
|
||||
} else {
|
||||
print("/listPlan ..");
|
||||
}
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFf5f5f5),
|
||||
// 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),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
Expanded(child: buildGroupListLayout(isDesktop)),
|
||||
],
|
||||
return PopScope(
|
||||
canPop: false, // Allow back navigation only if not login screen
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
_handleBackButton(); // Show exit confirmation dialog
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Color(0xFFf5f5f5),
|
||||
// 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),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (isDesktop) CustomDrawer(isDesktop: true),
|
||||
Expanded(child: buildGroupListLayout(isDesktop)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -114,9 +114,40 @@ class _PolicyState extends State<Policy> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadinitializeData();
|
||||
//
|
||||
// updateSelectedServices();
|
||||
// updateData();
|
||||
//
|
||||
// loadInitialData();
|
||||
//
|
||||
// if (widget.policy != null) {
|
||||
// final details = List<Map<String, dynamic>>.from(
|
||||
// widget.policy!['policy_details'],
|
||||
// );
|
||||
// policyCriteriaKey.currentState?.loadPolicyDetails(details);
|
||||
//
|
||||
// policyCriteriaKey.currentState?.fetchTrainFlightClass();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
loadinitializeData();
|
||||
|
||||
updateSelectedServices();
|
||||
@ -132,7 +163,9 @@ class _PolicyState extends State<Policy> {
|
||||
|
||||
policyCriteriaKey.currentState?.fetchTrainFlightClass();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
|
||||
@ -21,7 +21,8 @@ class PolicyList extends StatefulWidget {
|
||||
|
||||
class _PolicyListState extends State<PolicyList> {
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futurePolicy;
|
||||
// late Future<List<dynamic>> futurePolicy;
|
||||
Future<List<dynamic>>? futurePolicy;
|
||||
|
||||
late Map<String, dynamic> userSingleData;
|
||||
List<dynamic>? apiCountryData;
|
||||
@ -43,22 +44,50 @@ class _PolicyListState extends State<PolicyList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futurePolicy = fetchPolicy();
|
||||
|
||||
futurePolicy.then((object) {
|
||||
setState(() {
|
||||
allPolicy = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
fetchPolicy();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futurePolicy = fetchPolicy();
|
||||
//
|
||||
// futurePolicy.then((object) {
|
||||
// setState(() {
|
||||
// allPolicy = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// fetchPolicy();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futurePolicy = fetchPolicy();
|
||||
|
||||
futurePolicy?.then((object) {
|
||||
setState(() {
|
||||
allPolicy = object;
|
||||
});
|
||||
});
|
||||
|
||||
loadInitialData();
|
||||
fetchPolicy();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
@ -91,7 +120,7 @@ class _PolicyListState extends State<PolicyList> {
|
||||
setState(() {
|
||||
futurePolicy = fetchPolicy(); // Re-fetch users after status update
|
||||
|
||||
futurePolicy.then((object) {
|
||||
futurePolicy?.then((object) {
|
||||
setState(() {
|
||||
allPolicy = object;
|
||||
});
|
||||
@ -375,7 +404,7 @@ class _PolicyListState extends State<PolicyList> {
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
List<dynamic> policyData = await futurePolicy;
|
||||
List? policyData = await futurePolicy;
|
||||
|
||||
// Print the resolved value
|
||||
print("CREATELIAS - $policyData");
|
||||
@ -454,6 +483,10 @@ class _PolicyListState extends State<PolicyList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futurePolicy,
|
||||
builder: (context, snapshot) {
|
||||
if (futurePolicy == null) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -28,7 +28,8 @@ class TravellerListState extends State<TravellerList> {
|
||||
GlobalKey<TravellerListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureTraveller;
|
||||
Future<List<dynamic>>? futureTraveller;
|
||||
// late Future<List<dynamic>> futureTraveller;
|
||||
|
||||
late Map<String, dynamic> depSingleData;
|
||||
String? selectedTravellerId;
|
||||
@ -47,21 +48,50 @@ class TravellerListState extends State<TravellerList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureTraveller = fetchGetTraveller();
|
||||
|
||||
futureTraveller.then((object) {
|
||||
setState(() {
|
||||
allTraveller = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
_checkAuthAndLoadData();
|
||||
// futureTraveller = fetchGetTraveller();
|
||||
//
|
||||
// futureTraveller.then((object) {
|
||||
// setState(() {
|
||||
// allTraveller = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// });
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
futureTraveller = fetchGetTraveller();
|
||||
|
||||
futureTraveller?.then((object) {
|
||||
setState(() {
|
||||
allTraveller = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
String? layoutString = await getLayoutColor();
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
@ -89,7 +119,7 @@ class TravellerListState extends State<TravellerList> {
|
||||
|
||||
futureTraveller = fetchGetTraveller();
|
||||
|
||||
return futureTraveller.then((object) {
|
||||
return futureTraveller!.then((object) {
|
||||
print("Calling Refresh Data $object");
|
||||
setState(() {
|
||||
allTraveller = object;
|
||||
@ -147,23 +177,25 @@ class TravellerListState extends State<TravellerList> {
|
||||
final lowerQuery = query.toLowerCase().trim();
|
||||
|
||||
setState(() {
|
||||
filteredTraveller = allTraveller.where((object) {
|
||||
final travellerId = object['traveller_id']?.toLowerCase() ?? '';
|
||||
final firstName = object['first_name']?.toLowerCase() ?? '';
|
||||
final lastName = object['last_name']?.toLowerCase() ?? '';
|
||||
final fullName = '$firstName $lastName';
|
||||
final mobile = object['mobile']?.toLowerCase() ?? '';
|
||||
final email = object['email']?.toLowerCase() ?? '';
|
||||
final isActiveStatus = object['is_active'] == "1" ? "active" : "inactive";
|
||||
filteredTraveller =
|
||||
allTraveller.where((object) {
|
||||
final travellerId = object['traveller_id']?.toLowerCase() ?? '';
|
||||
final firstName = object['first_name']?.toLowerCase() ?? '';
|
||||
final lastName = object['last_name']?.toLowerCase() ?? '';
|
||||
final fullName = '$firstName $lastName';
|
||||
final mobile = object['mobile']?.toLowerCase() ?? '';
|
||||
final email = object['email']?.toLowerCase() ?? '';
|
||||
final isActiveStatus =
|
||||
object['is_active'] == "1" ? "active" : "inactive";
|
||||
|
||||
return travellerId.contains(lowerQuery) ||
|
||||
firstName.contains(lowerQuery) ||
|
||||
lastName.contains(lowerQuery) ||
|
||||
fullName.contains(lowerQuery) ||
|
||||
mobile.contains(lowerQuery) ||
|
||||
email.contains(lowerQuery) ||
|
||||
isActiveStatus.contains(lowerQuery);
|
||||
}).toList();
|
||||
return travellerId.contains(lowerQuery) ||
|
||||
firstName.contains(lowerQuery) ||
|
||||
lastName.contains(lowerQuery) ||
|
||||
fullName.contains(lowerQuery) ||
|
||||
mobile.contains(lowerQuery) ||
|
||||
email.contains(lowerQuery) ||
|
||||
isActiveStatus.contains(lowerQuery);
|
||||
}).toList();
|
||||
currentPage = 0;
|
||||
});
|
||||
print("filteredTraveller: $filteredTraveller");
|
||||
@ -411,6 +443,10 @@ class TravellerListState extends State<TravellerList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureTraveller,
|
||||
builder: (context, snapshot) {
|
||||
if (futureTraveller == null) {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
|
||||
@ -56,6 +56,8 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
String? orgId;
|
||||
String? userIdApi;
|
||||
|
||||
bool isCheckingToken = false;
|
||||
|
||||
String? token;
|
||||
|
||||
late bool isapiselectedUser = false;
|
||||
@ -152,10 +154,10 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
"date_of_birth": controllers["dob"]?.text,
|
||||
"address": controllers["address"]?.text,
|
||||
"gender": selectedGender,
|
||||
|
||||
// "gender": personalDetailsKey.currentState?.selectedGender,
|
||||
// "agent_supported_service_ids": selectedServiceIds,
|
||||
"agent_supported_service_ids": selectedServiceIds,
|
||||
|
||||
"postal_code": controllers["postalCode"]?.text,
|
||||
"country_code": selectedCountry,
|
||||
"employee_code": controllers["employeeCode"]?.text,
|
||||
@ -338,27 +340,181 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
}
|
||||
|
||||
@override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// prepareForNewEntry();
|
||||
// selectedTab = "personal";
|
||||
//
|
||||
// // WidgetsFlutterBinding.ensureInitialized();
|
||||
//
|
||||
// // Step 1: Set 'reloaded' flag before page unload
|
||||
// // html.window.onBeforeUnload.listen((event) {
|
||||
// // html.window.localStorage['reloaded'] = 'true';
|
||||
// // });
|
||||
//
|
||||
// apiCountryData = null;
|
||||
// apiUserData = null;
|
||||
// // apiselectedUser = null;
|
||||
// apiCostData = null;
|
||||
// apiRoleData = null;
|
||||
//
|
||||
// // Initialize controllers for each field
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// // final wasReloaded = html.window.localStorage['reloaded'] == 'true';
|
||||
// //
|
||||
// // if (wasReloaded) {
|
||||
// // html.window.localStorage.remove('reloaded'); // Clear it
|
||||
// // context.go('/listUser'); // Navigate using go_router
|
||||
// // }
|
||||
//
|
||||
// final extraData =
|
||||
// GoRouterState.of(context).extra as Map<String, dynamic>?;
|
||||
//
|
||||
// if (extraData != null) {
|
||||
// print("extraData: ${extraData['selectedUser']}");
|
||||
//
|
||||
// setState(() {
|
||||
// // apiCountryData = extraData['apiCountryData'];
|
||||
// // apiUserData = extraData['apiUserData'];
|
||||
// //
|
||||
// // userList = apiUserData ?? [];
|
||||
// // userMap = {
|
||||
// // for (var user in userList)
|
||||
// // user['user_id'].toString(): "${user['first_name']} ${user['last_name']}"
|
||||
// // };
|
||||
// // userIdsApi = userMap.keys.toList();
|
||||
//
|
||||
// // Handle selectedUser as a Map (not a List)
|
||||
// apiselectedUser =
|
||||
// extraData['selectedUser']
|
||||
// as Map<String, dynamic>?; // Cast it as a Map
|
||||
// isViewMode = extraData['isViewMode'] ?? false;
|
||||
// isEditProfile = extraData['isEditProfile'] ?? false;
|
||||
// });
|
||||
//
|
||||
// print("selectedUser: $apiselectedUser");
|
||||
//
|
||||
// // Add another post-frame callback to check after setState
|
||||
// // await Future.delayed(Duration(
|
||||
// // milliseconds: 100)); // Optional delay to ensure UI has updated
|
||||
// updateData();
|
||||
// }
|
||||
//
|
||||
// initializeData();
|
||||
// fetchCountries();
|
||||
// fetchDepartment();
|
||||
// fetchUsers();
|
||||
// fetchRoles();
|
||||
// loadInitialData();
|
||||
// });
|
||||
//
|
||||
// for (var field in dataHeader) {
|
||||
// controllers[field] = TextEditingController();
|
||||
// }
|
||||
// }
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
isCheckingToken = true;
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_checkAuthAndLoadData(); // Safe place to use context
|
||||
});
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData() async {
|
||||
setState(() {
|
||||
isCheckingToken = true;
|
||||
});
|
||||
|
||||
final String? token = await getToken();
|
||||
if (!mounted) return;
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
context.go("/");
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isCheckingToken = false;
|
||||
});
|
||||
|
||||
prepareForNewEntry();
|
||||
selectedTab = "personal";
|
||||
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Step 1: Set 'reloaded' flag before page unload
|
||||
// html.window.onBeforeUnload.listen((event) {
|
||||
// html.window.localStorage['reloaded'] = 'true';
|
||||
// });
|
||||
|
||||
apiCountryData = null;
|
||||
apiUserData = null;
|
||||
// apiselectedUser = null;
|
||||
apiCostData = null;
|
||||
apiRoleData = null;
|
||||
|
||||
// Initialize controllers for each field
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
/// ✅ Now this is safe here
|
||||
try {
|
||||
final extraData = GoRouterState.of(context).extra;
|
||||
if (extraData != null && extraData is Map<String, dynamic>) {
|
||||
setState(() {
|
||||
apiselectedUser = extraData['selectedUser'] as Map<String, dynamic>?;
|
||||
isViewMode = extraData['isViewMode'] ?? false;
|
||||
isEditProfile = extraData['isEditProfile'] ?? false;
|
||||
});
|
||||
updateData();
|
||||
}
|
||||
} catch (e) {
|
||||
print("Router extra error: $e");
|
||||
}
|
||||
|
||||
// Final async data fetches
|
||||
initializeData();
|
||||
fetchCountries();
|
||||
fetchDepartment();
|
||||
fetchUsers();
|
||||
fetchRoles();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
void _checkAuthAndLoadData22() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
setState(() {
|
||||
isCheckingToken = false;
|
||||
});
|
||||
|
||||
return;
|
||||
} else {
|
||||
if (!mounted) return;
|
||||
|
||||
// Future.microtask(() {
|
||||
prepareForNewEntry();
|
||||
selectedTab = "personal";
|
||||
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Step 1: Set 'reloaded' flag before page unload
|
||||
// html.window.onBeforeUnload.listen((event) {
|
||||
// html.window.localStorage['reloaded'] = 'true';
|
||||
// });
|
||||
|
||||
apiCountryData = null;
|
||||
apiUserData = null;
|
||||
// apiselectedUser = null;
|
||||
apiCostData = null;
|
||||
apiRoleData = null;
|
||||
|
||||
// Initialize controllers for each field
|
||||
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// if (!mounted) return;
|
||||
// final wasReloaded = html.window.localStorage['reloaded'] == 'true';
|
||||
//
|
||||
// if (wasReloaded) {
|
||||
@ -405,10 +561,16 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
fetchUsers();
|
||||
fetchRoles();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isCheckingToken = false;
|
||||
});
|
||||
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@ -952,9 +1114,15 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
// ✅ Encode travel_details as a proper JSON string
|
||||
request.fields[key] = jsonEncode(value);
|
||||
|
||||
print("✅ Encoded travel_details: ${request.fields[key]}");
|
||||
print("✅ Encoded travel_details1: ${request.fields[key]}");
|
||||
} else if (key == 'agent_supported_service_ids' && value is List) {
|
||||
request.fields[key] = jsonEncode(value);
|
||||
print("✅ Encoded agent_supported_service_ids: ${request.fields[key]}");
|
||||
} else {
|
||||
// request.fields[key] = jsonEncode(value);
|
||||
print("✅ Encoded travel_details:${key} - ${value}");
|
||||
request.fields[key] = value.toString();
|
||||
print("✅ Encoded travel_details2: ${request.fields[key]}");
|
||||
}
|
||||
// }
|
||||
});
|
||||
@ -1043,6 +1211,10 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
if (isCheckingToken) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFf5f5f5),
|
||||
// appBar: isDesktop ? null : const CustomAppBar(title: 'Create User '),
|
||||
|
||||
@ -452,8 +452,12 @@ class PersonalDetailsState extends State<PersonalDetails> {
|
||||
selectedServiceIds.add({"service_id": serviceId});
|
||||
}
|
||||
print("selectedServiceIdsUser --- $selectedServiceIds");
|
||||
print(
|
||||
"selectedServiceIdsUser1 --- ${json.encode(selectedServiceIds)}",
|
||||
);
|
||||
// Call the parent's callback
|
||||
widget.onServiceIdsChanged!(selectedServiceIds);
|
||||
// widget.onServiceIdsChanged!(selectedServiceIds);
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
|
||||
@ -2377,6 +2377,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
|
||||
CustomTextFieldUserTravellerWrapper(
|
||||
width:
|
||||
widget.isDesktop
|
||||
@ -2675,14 +2676,14 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
selectedItem['dropdown_value'] ?? 'Select Seat"',
|
||||
selectedItem['dropdown_value'] ?? 'Select Seat',
|
||||
style: GoogleFonts.poppins(fontSize: 12, color: Colors.black),
|
||||
);
|
||||
},
|
||||
items: seatOptionsInt,
|
||||
selectedItem:
|
||||
selectedIntenationalSeat == null
|
||||
? {"dropdown_value": "Select Seat"}
|
||||
? null
|
||||
: {"dropdown_value": selectedIntenationalSeat},
|
||||
onChanged:
|
||||
widget.isViewMode
|
||||
@ -3673,7 +3674,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
" * I confirm my passport is valid for next 6 months",
|
||||
" * confirm your passport is valid for next 6 months",
|
||||
style: GoogleFonts.poppins(fontSize: 10),
|
||||
),
|
||||
IconForVisa(),
|
||||
|
||||
@ -46,20 +46,45 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
futureUsers = fetchUsers();
|
||||
// futureUsers = fetchUsers();
|
||||
//
|
||||
// futureUsers.then((users) {
|
||||
// setState(() {
|
||||
// allUsers = users;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
_checkAuthAndLoadData();
|
||||
}
|
||||
|
||||
futureUsers.then((users) {
|
||||
setState(() {
|
||||
allUsers = users;
|
||||
void _checkAuthAndLoadData() async {
|
||||
final String? token = await getToken(); // Your async function to get token
|
||||
|
||||
if (token == null || token.isEmpty) {
|
||||
// Token doesn't exist → redirect to login
|
||||
context.go(
|
||||
"/",
|
||||
); // or use: router.go("/") if you're using `GoRouter` directly
|
||||
return;
|
||||
} else {
|
||||
futureUsers = fetchUsers();
|
||||
|
||||
futureUsers.then((users) {
|
||||
setState(() {
|
||||
allUsers = users;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -194,8 +219,7 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
print("handDel - $userId");
|
||||
}
|
||||
|
||||
Future<void> handleUpload ()async {
|
||||
|
||||
Future<void> handleUpload() async {
|
||||
final String apiUrldata = '$apiUrl/api/user/userUpload'; // api
|
||||
final String? token = await getToken(); // 2kn
|
||||
|
||||
@ -227,7 +251,6 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (reader.readyState == html.FileReader.DONE) {
|
||||
Uint8List? fileBytes = reader.result as Uint8List?;
|
||||
if (fileBytes != null) {
|
||||
@ -253,15 +276,23 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
// formData.appendBlob('file', html.Blob([fileBytes]), fileName);
|
||||
|
||||
// Create a multipart request
|
||||
final request = http.MultipartRequest('POST', Uri.parse(apiUrldata));
|
||||
final request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(apiUrldata),
|
||||
);
|
||||
|
||||
// Attach the file to the request
|
||||
// Set authorization token in headers
|
||||
request.headers['Authorization'] = 'Bearer $token';
|
||||
// request.files.add(http.MultipartFile.fromBytes('file', fileBytes, filename: fileName));
|
||||
|
||||
request.files.add(http.MultipartFile.fromBytes( 'user_file', fileBytes, filename: 'user_file.xlsx' ));
|
||||
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes(
|
||||
'user_file',
|
||||
fileBytes,
|
||||
filename: 'user_file.xlsx',
|
||||
),
|
||||
);
|
||||
|
||||
print('request : $request');
|
||||
// Send the request
|
||||
@ -446,6 +477,10 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
// Refresh user list after update
|
||||
void refreshUserList() {
|
||||
setState(() {
|
||||
print("Search cleared 1");
|
||||
searchController.clear(); // or wrap in setState if needed
|
||||
print("Search cleared - ${searchController.text}");
|
||||
filteredUsers = [];
|
||||
futureUsers = fetchUsers();
|
||||
|
||||
futureUsers.then((users) {
|
||||
@ -573,8 +608,9 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.15),
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.23),
|
||||
|
||||
// SizedBox(width: MediaQuery.of(context).size.width * 0.15),
|
||||
if (isDesktop)
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width * 0.2,
|
||||
@ -616,27 +652,62 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
),
|
||||
// SizedBox(width: 16),
|
||||
Spacer(),
|
||||
OutlinedButton(
|
||||
onPressed: () { apiService.getDownloadUserTemplateForUpload(); },
|
||||
style: OutlinedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Color(0xFF114D8B),
|
||||
side: BorderSide(color: Colors.white),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
|
||||
// OutlinedButton(
|
||||
// onPressed: () {
|
||||
// apiService.getDownloadUserTemplateForUpload();
|
||||
// },
|
||||
// style: OutlinedButton.styleFrom(
|
||||
// backgroundColor: Colors.white,
|
||||
// foregroundColor: Color(0xFF114D8B),
|
||||
// side: BorderSide(color: Colors.white),
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: 20,
|
||||
// vertical: 16,
|
||||
// ),
|
||||
// ),
|
||||
// child: Text("Sample Template Download"),
|
||||
// ),
|
||||
IconButton(
|
||||
icon: Image.asset(
|
||||
'assets/images/IconsImg/download.png',
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
child: Text("Sample Template Download"),
|
||||
), Spacer(),
|
||||
tooltip: 'Sample Template Download',
|
||||
onPressed: () {
|
||||
apiService.getDownloadUserTemplateForUpload();
|
||||
},
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
|
||||
// Upload Button
|
||||
OutlinedButton(
|
||||
onPressed: handleUpload,
|
||||
style: OutlinedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Color(0xFF114D8B),
|
||||
side: BorderSide(color: Colors.white),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
// OutlinedButton(
|
||||
// onPressed: handleUpload,
|
||||
// style: OutlinedButton.styleFrom(
|
||||
// backgroundColor: Colors.white,
|
||||
// foregroundColor: Color(0xFF114D8B),
|
||||
// side: BorderSide(color: Colors.white),
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: 20,
|
||||
// vertical: 16,
|
||||
// ),
|
||||
// ),
|
||||
// child: Text("User Bulk Upload"),
|
||||
// ),
|
||||
IconButton(
|
||||
icon: Image.asset(
|
||||
'assets/images/IconsImg/upload.png',
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
child: Text("User Bulk Upload"),
|
||||
), Spacer(),
|
||||
tooltip: 'User Bulk Upload',
|
||||
onPressed: () {
|
||||
handleUpload();
|
||||
},
|
||||
),
|
||||
// Spacer(),
|
||||
SizedBox(width: 5),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF114D8B),
|
||||
|
||||
87
lib/app.dart
87
lib/app.dart
@ -2,7 +2,7 @@ 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';
|
||||
@ -31,10 +31,12 @@ class _MyAppState extends State<MyApp> {
|
||||
@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' &&
|
||||
print("URI - $uri");
|
||||
|
||||
if (uri.path == '/tstat/authredirection' &&
|
||||
uri.queryParameters['code'] != null) {
|
||||
_authCode = uri.queryParameters['code'];
|
||||
// _isAuthRedirect = true;
|
||||
@ -51,7 +53,7 @@ class _MyAppState extends State<MyApp> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleTokenUsingMS(authCode) async {
|
||||
Future<void> handleTokenUsingMS(String? authCode) async {
|
||||
if (authCode == null) return;
|
||||
|
||||
final url = '$apiUrl/auth/verifyMSAuthUser?code=$authCode';
|
||||
@ -62,10 +64,11 @@ class _MyAppState extends State<MyApp> {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final MS_Token = json.decode(response.body)['token'];
|
||||
final responseBody = json.decode(response.body);
|
||||
final MS_Token = responseBody['token'];
|
||||
print("MS_Token - $MS_Token");
|
||||
|
||||
if (MS_Token != '') {
|
||||
if (MS_Token != null && MS_Token != '') {
|
||||
print('Microsoft - Token Available');
|
||||
await storeUserDetails(MS_Token);
|
||||
|
||||
@ -79,20 +82,78 @@ class _MyAppState extends State<MyApp> {
|
||||
router.go('/listPlan');
|
||||
}
|
||||
} else {
|
||||
print('Microsoft - Token Not Available');
|
||||
throw Exception('Token not Founded');
|
||||
throw Exception('Token not found in response.');
|
||||
}
|
||||
} else {
|
||||
final errorMessage = json.decode(response.body)['message'];
|
||||
print(errorMessage);
|
||||
throw Exception(errorMessage);
|
||||
// Handle 400/401/500 etc.
|
||||
String errorMsg;
|
||||
try {
|
||||
final decoded = json.decode(response.body);
|
||||
errorMsg = decoded['message'] ?? 'Unknown error';
|
||||
} catch (_) {
|
||||
errorMsg = response.body; // fallback to plain text
|
||||
}
|
||||
|
||||
print("Error response: $errorMsg");
|
||||
throw Exception("Authentication failed: $errorMsg");
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stack) {
|
||||
print("Caught error: $e");
|
||||
router.go('/');
|
||||
print("Error: $e");
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> handleTokenUsingMS(authCode) async {
|
||||
// if (authCode == null) return;
|
||||
//
|
||||
// final url = '$apiUrl/auth/verifyMSAuthUser?code=$authCode';
|
||||
// try {
|
||||
// final response = await http.get(
|
||||
// Uri.parse(url),
|
||||
// headers: {'Content-Type': 'application/json'},
|
||||
// );
|
||||
//
|
||||
// if (response.statusCode == 200) {
|
||||
// final MS_Token = json.decode(response.body)['token'];
|
||||
// print("MS_Token - $MS_Token");
|
||||
//
|
||||
// if (MS_Token != '') {
|
||||
// print('Microsoft - Token Available');
|
||||
// await storeUserDetails(MS_Token);
|
||||
//
|
||||
// print("userRole - $userRole");
|
||||
//
|
||||
// if (userRole == "Travel Agent") {
|
||||
// router.go('/listTravelAgentPlan');
|
||||
// } else if (userRole == "Org Admin" || userRole == "Travel Admin") {
|
||||
// router.go('/listAllPlan');
|
||||
// } else {
|
||||
// router.go('/listPlan');
|
||||
// }
|
||||
// } else {
|
||||
// print('Microsoft - Token Not Available');
|
||||
// throw Exception('Token not Founded');
|
||||
// }
|
||||
// } else {
|
||||
// // final errorMessage = json.decode(response.body)['message'];
|
||||
// // print(errorMessage);
|
||||
// // throw Exception(errorMessage);
|
||||
//
|
||||
// try {
|
||||
// final errorMessage = json.decode(response.body)['message'];
|
||||
// print(errorMessage);
|
||||
// throw Exception(errorMessage);
|
||||
// } catch (_) {
|
||||
// print("Non-JSON error from server: ${response.body}");
|
||||
// throw Exception("Authentication failed: ${response.body}");
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// router.go('/');
|
||||
// print("Error: $e");
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> storeUserDetails(String token) async {
|
||||
try {
|
||||
final parts = token.split('.');
|
||||
|
||||
@ -295,326 +295,355 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
context.go('/');
|
||||
}
|
||||
|
||||
void _handleBackButton() {
|
||||
if (selectedTab == TabSelection.dashboard) {
|
||||
// Do nothing or show "Press again to exit" toast
|
||||
print("Blocked back on dashboard");
|
||||
} else {
|
||||
setState(() {
|
||||
selectedTab = TabSelection.dashboard;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
surfaceTintColor: Colors.white,
|
||||
// elevation: 3,
|
||||
automaticallyImplyLeading: !widget.isDesktop,
|
||||
iconTheme: IconThemeData(
|
||||
color: layoutColor, // 👈 Set your desired icon color here
|
||||
),
|
||||
return PopScope(
|
||||
canPop: false, // Allow back navigation only if not login screen
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
_handleBackButton(); // Show exit confirmation dialog
|
||||
},
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
surfaceTintColor: Colors.white,
|
||||
// elevation: 3,
|
||||
automaticallyImplyLeading: !widget.isDesktop,
|
||||
iconTheme: IconThemeData(
|
||||
color: layoutColor, // 👈 Set your desired icon color here
|
||||
),
|
||||
|
||||
titleSpacing: 0,
|
||||
titleSpacing: 0,
|
||||
|
||||
title:
|
||||
!widget.isDesktop
|
||||
? Text('')
|
||||
: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.05,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
title:
|
||||
!widget.isDesktop
|
||||
? Text('')
|
||||
: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
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
|
||||
? SizedBox(
|
||||
height: 50,
|
||||
child: ClipRect(
|
||||
child: Image.network(
|
||||
selectedOrg!['logo'],
|
||||
width: 130, //130
|
||||
height: 80, //80
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const CircleAvatar(
|
||||
radius: 20,
|
||||
child: Icon(
|
||||
Icons.add_a_photo,
|
||||
size: 10,
|
||||
color: Colors.grey,
|
||||
),
|
||||
// backgroundColor: Colors.redAccent,
|
||||
// child: Icon(Icons.error, size: 10),
|
||||
);
|
||||
},
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
|
||||
child:
|
||||
selectedOrg?['logo'] != null
|
||||
? SizedBox(
|
||||
height: 50,
|
||||
child: ClipRect(
|
||||
child: Image.network(
|
||||
selectedOrg!['logo'],
|
||||
width: 130, //130
|
||||
height: 80, //80
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (
|
||||
context,
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
return const CircleAvatar(
|
||||
radius: 20,
|
||||
child: Icon(
|
||||
Icons.add_a_photo,
|
||||
size: 10,
|
||||
color: Colors.grey,
|
||||
),
|
||||
// backgroundColor: Colors.redAccent,
|
||||
// child: Icon(Icons.error, size: 10),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
: const CircleAvatar(
|
||||
radius: 20,
|
||||
// backgroundColor: Colors.white,
|
||||
child: Icon(
|
||||
Icons.add_a_photo,
|
||||
size: 10,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const CircleAvatar(
|
||||
radius: 20,
|
||||
// backgroundColor: Colors.white,
|
||||
child: Icon(
|
||||
Icons.add_a_photo,
|
||||
size: 10,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.18),
|
||||
// Spacer(),
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width * 0.35,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
"Dashboard",
|
||||
() => handleTabChange(
|
||||
TabSelection.dashboard,
|
||||
'/StatusDashboard',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.dashboard,
|
||||
icon: Icons.dashboard,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
"All Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.allTrips,
|
||||
'/listAllPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.allTrips,
|
||||
icon: Icons.format_list_bulleted_rounded,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
if (userDetails["role"] != "Travel Agent")
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] == "Travel Agent")
|
||||
buildNavItem(
|
||||
"Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips,
|
||||
'/listTravelAgentPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listTravelAgentPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
icon: Icons.shopping_bag_outlined,
|
||||
// icon: Icons.request_page_outlined,
|
||||
),
|
||||
if (userData?["role"] != "Travel Agent") // for others
|
||||
buildNavItem(
|
||||
"My Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips,
|
||||
'/listPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
icon: Icons.shopping_bag_outlined,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] != "Travel Agent")
|
||||
buildNavItem(
|
||||
"My Approvals",
|
||||
|
||||
() => handleTabChange(
|
||||
TabSelection.myApprovals,
|
||||
'/ApprovalList',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/ApprovalList'),
|
||||
isSelected:
|
||||
selectedTab == TabSelection.myApprovals,
|
||||
icon: Icons.verified_outlined,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.055,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (userData?["role"] != "User")
|
||||
Builder(
|
||||
builder:
|
||||
(context) => PopupMenuButton<String>(
|
||||
color: Colors.white,
|
||||
padding: EdgeInsets.zero,
|
||||
offset: const Offset(0, 50), // 👈 shift it 50 pixels down
|
||||
onSelected: (String value) {
|
||||
switch (value) {
|
||||
case '/OrganizationSettings':
|
||||
context.go('/OrganizationSettings');
|
||||
break;
|
||||
// case '/OrganizationSetup':
|
||||
// context.go('/OrganizationSetup');
|
||||
// break;
|
||||
case '/listUser':
|
||||
context.go('/listUser');
|
||||
break;
|
||||
case '/report':
|
||||
context.go('/report');
|
||||
break;
|
||||
// case '/department':
|
||||
// context.go('/department');
|
||||
// break;
|
||||
// case '/PolicyList':
|
||||
// context.go('/PolicyList');
|
||||
// case '/getPerdiem':
|
||||
// context.go('/getPerdiem');
|
||||
// case '/templateList':
|
||||
// context.go('/templateList');
|
||||
// case '/template':
|
||||
// context.go('/template');
|
||||
|
||||
case '/CreateUserDetails':
|
||||
context.go(
|
||||
"/CreateUserDetails",
|
||||
extra: {
|
||||
"selectedUser": profileUserDetails,
|
||||
"isEditProfile": true,
|
||||
"isViewMode": false,
|
||||
},
|
||||
);
|
||||
case '/logout':
|
||||
logout(context);
|
||||
// context.go('/');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// 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) =>
|
||||
item['value'] == '/CreateUserDetails' ||
|
||||
item['value'] == '/logout',
|
||||
)
|
||||
.toList();
|
||||
} else if (role == "Travel Agent") {
|
||||
filteredItems =
|
||||
menuItems
|
||||
.where((item) => item['value'] == '/logout')
|
||||
.toList();
|
||||
} else {
|
||||
filteredItems = menuItems;
|
||||
}
|
||||
|
||||
// Create a new list starting with role display and divider
|
||||
return [
|
||||
PopupMenuItem<String>(
|
||||
enabled: false, // ❌ Not clickable
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
userData?["role"] ?? '',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
// const Divider(), // 👈 Divider after role
|
||||
],
|
||||
),
|
||||
),
|
||||
...filteredItems
|
||||
.map(buildMenuItem)
|
||||
.toList(), // 👈 then normal items
|
||||
// const PopupMenuDivider(),
|
||||
PopupMenuItem<String>(
|
||||
enabled: false, // Not clickable
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Last Login : ",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
|
||||
// SizedBox(width: 10),
|
||||
Text(
|
||||
"${userData?["last_login_at"] ?? ''}",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.18),
|
||||
// Spacer(),
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width * 0.35,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
userData?["name"] ?? "N/A",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black,
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
"Dashboard",
|
||||
() => handleTabChange(
|
||||
TabSelection.dashboard,
|
||||
'/StatusDashboard',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected:
|
||||
selectedTab == TabSelection.dashboard,
|
||||
icon: Icons.dashboard,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
"All Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.allTrips,
|
||||
'/listAllPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected:
|
||||
selectedTab == TabSelection.allTrips,
|
||||
icon: Icons.format_list_bulleted_rounded,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
if (userDetails["role"] != "Travel Agent")
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] == "Travel Agent")
|
||||
buildNavItem(
|
||||
"Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips,
|
||||
'/listTravelAgentPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listTravelAgentPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
icon: Icons.shopping_bag_outlined,
|
||||
// icon: Icons.request_page_outlined,
|
||||
),
|
||||
if (userData?["role"] !=
|
||||
"Travel Agent") // for others
|
||||
buildNavItem(
|
||||
"My Trips",
|
||||
() => handleTabChange(
|
||||
TabSelection.myTrips,
|
||||
'/listPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/listPlan'),
|
||||
isSelected: selectedTab == TabSelection.myTrips,
|
||||
icon: Icons.shopping_bag_outlined,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] != "Travel Agent")
|
||||
buildNavItem(
|
||||
"My Approvals",
|
||||
|
||||
() => handleTabChange(
|
||||
TabSelection.myApprovals,
|
||||
'/ApprovalList',
|
||||
),
|
||||
layoutColor!,
|
||||
// () => context.go('/ApprovalList'),
|
||||
isSelected:
|
||||
selectedTab == TabSelection.myApprovals,
|
||||
icon: Icons.verified_outlined,
|
||||
),
|
||||
// style: const TextStyle(
|
||||
// fontSize: 14,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontFamily: "Roboto",
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
),
|
||||
const Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 20,
|
||||
color: Colors.black87,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.055,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// if (userData?["role"] != "User")
|
||||
Builder(
|
||||
builder:
|
||||
(context) => PopupMenuButton<String>(
|
||||
color: Colors.white,
|
||||
padding: EdgeInsets.zero,
|
||||
offset: const Offset(
|
||||
0,
|
||||
50,
|
||||
), // 👈 shift it 50 pixels down
|
||||
onSelected: (String value) {
|
||||
switch (value) {
|
||||
case '/OrganizationSettings':
|
||||
context.go('/OrganizationSettings');
|
||||
break;
|
||||
// case '/OrganizationSetup':
|
||||
// context.go('/OrganizationSetup');
|
||||
// break;
|
||||
case '/listUser':
|
||||
context.go('/listUser');
|
||||
break;
|
||||
case '/report':
|
||||
context.go('/report');
|
||||
break;
|
||||
// case '/department':
|
||||
// context.go('/department');
|
||||
// break;
|
||||
// case '/PolicyList':
|
||||
// context.go('/PolicyList');
|
||||
// case '/getPerdiem':
|
||||
// context.go('/getPerdiem');
|
||||
// case '/templateList':
|
||||
// context.go('/templateList');
|
||||
// case '/template':
|
||||
// context.go('/template');
|
||||
|
||||
case '/CreateUserDetails':
|
||||
context.go(
|
||||
"/CreateUserDetails",
|
||||
extra: {
|
||||
"selectedUser": profileUserDetails,
|
||||
"isEditProfile": true,
|
||||
"isViewMode": false,
|
||||
},
|
||||
);
|
||||
case '/logout':
|
||||
logout(context);
|
||||
// context.go('/');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// 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) =>
|
||||
item['value'] ==
|
||||
'/CreateUserDetails' ||
|
||||
item['value'] == '/logout',
|
||||
)
|
||||
.toList();
|
||||
} else if (role == "Travel Agent") {
|
||||
filteredItems =
|
||||
menuItems
|
||||
.where((item) => item['value'] == '/logout')
|
||||
.toList();
|
||||
} else {
|
||||
filteredItems = menuItems;
|
||||
}
|
||||
|
||||
// Create a new list starting with role display and divider
|
||||
return [
|
||||
PopupMenuItem<String>(
|
||||
enabled: false, // ❌ Not clickable
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
userData?["role"] ?? '',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
// const Divider(), // 👈 Divider after role
|
||||
],
|
||||
),
|
||||
),
|
||||
...filteredItems
|
||||
.map(buildMenuItem)
|
||||
.toList(), // 👈 then normal items
|
||||
// const PopupMenuDivider(),
|
||||
PopupMenuItem<String>(
|
||||
enabled: false, // Not clickable
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Last Login : ",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
|
||||
// SizedBox(width: 10),
|
||||
Text(
|
||||
"${userData?["last_login_at"] ?? ''}",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
userData?["name"] ?? "N/A",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black,
|
||||
),
|
||||
// style: const TextStyle(
|
||||
// fontSize: 14,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontFamily: "Roboto",
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
),
|
||||
const Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 20,
|
||||
color: Colors.black87,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size.fromHeight(1),
|
||||
child: Container(
|
||||
height: 1,
|
||||
// color: Colors.grey.shade200, // Set the color of the bottom border
|
||||
color: layoutColor, // Set the color of the bottom border
|
||||
),
|
||||
),
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size.fromHeight(1),
|
||||
child: Container(
|
||||
height: 1,
|
||||
// color: Colors.grey.shade200, // Set the color of the bottom border
|
||||
color: layoutColor, // Set the color of the bottom border
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -105,6 +105,8 @@ flutter:
|
||||
- assets/images/IconsImg/Frame.png
|
||||
- assets/images/IconsImg/delete.png
|
||||
- assets/images/IconsImg/edit.png
|
||||
- assets/images/IconsImg/upload.png
|
||||
- assets/images/IconsImg/download.png
|
||||
- assets/images/IconsImg/planPdf_icon.png
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user