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();
|
||||
|
||||
@ -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,9 +48,37 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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) {
|
||||
futureCostCenter?.then((object) {
|
||||
setState(() {
|
||||
allCostCenter = object;
|
||||
});
|
||||
@ -58,8 +87,9 @@ class CostCenterListState extends State<CostCenterList> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -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 {
|
||||
|
||||
|
||||
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,
|
||||
fontSize:
|
||||
(title == 'Domestic' || title == 'International')
|
||||
? 16
|
||||
: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@ -182,22 +280,42 @@ 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(
|
||||
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
|
||||
padding:
|
||||
isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width * 0.1, // 30% of screen width as horizontal padding
|
||||
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),
|
||||
@ -208,10 +326,14 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: IntrinsicHeight( // Only needed if child layout depends on height
|
||||
child: IntrinsicHeight(
|
||||
// Only needed if child layout depends on height
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isDesktop ? Colors.white : const Color(0xFFFCFCFC),
|
||||
color:
|
||||
isDesktop
|
||||
? Colors.white
|
||||
: const Color(0xFFFCFCFC),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
@ -220,19 +342,34 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
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
|
||||
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),
|
||||
child: buildInfoCard(
|
||||
item['value'],
|
||||
item['count'],
|
||||
cardWidth,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
@ -240,18 +377,31 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
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
|
||||
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),
|
||||
child: buildInfoCard(
|
||||
item['value'],
|
||||
item['count'],
|
||||
cardWidth,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -263,14 +413,11 @@ class StatusDashboardState extends State<StatusDashboard> {
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,9 +48,37 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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) {
|
||||
futureDepartment?.then((object) {
|
||||
setState(() {
|
||||
allDepartment = object;
|
||||
});
|
||||
@ -58,8 +87,9 @@ class DepartmentListState extends State<DepartmentList> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -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,9 +50,38 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
// futureForex = fetchGetForex();
|
||||
//
|
||||
// futureForex.then((users) {
|
||||
// setState(() {
|
||||
// allForex = users;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// 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 {
|
||||
futureForex = fetchGetForex();
|
||||
|
||||
futureForex.then((users) {
|
||||
futureForex?.then((users) {
|
||||
setState(() {
|
||||
allForex = users;
|
||||
});
|
||||
@ -61,16 +91,33 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> refreshData() {
|
||||
// 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,7 +798,8 @@ class ForexDataListState extends State<ForexDataList> {
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
color: forex['is_active'] == "1"
|
||||
color:
|
||||
forex['is_active'] == "1"
|
||||
? Colors.green
|
||||
: Colors.grey,
|
||||
),
|
||||
|
||||
@ -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();
|
||||
_checkAuthAndLoadData();
|
||||
// futureGroups = fetchGroups();
|
||||
//
|
||||
// futureGroups.then((object) {
|
||||
// setState(() {
|
||||
// allGroups = object;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// loadInitialData();
|
||||
// fetchGroups();
|
||||
// loadAllGroups();
|
||||
// });
|
||||
|
||||
// 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) {
|
||||
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,9 +50,38 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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) {
|
||||
futureHotels?.then((objects) {
|
||||
setState(() {
|
||||
allHotels = objects;
|
||||
});
|
||||
@ -61,8 +91,9 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> refreshData() {
|
||||
@ -70,7 +101,7 @@ class HotelsDataListState extends State<HotelsDataList> {
|
||||
|
||||
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,7 +102,29 @@ class TemplateState extends State<Template> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
//
|
||||
// for (var field in dataHeader) {
|
||||
// controllers[field] = TextEditingController();
|
||||
// }
|
||||
//
|
||||
// updateData();
|
||||
// loadinitializeData();
|
||||
// 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;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
@ -110,6 +132,9 @@ class TemplateState extends State<Template> {
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -108,7 +108,29 @@ class TemplateForexState extends State<TemplateForex> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
//
|
||||
// for (var field in dataHeader) {
|
||||
// controllers[field] = TextEditingController();
|
||||
// }
|
||||
//
|
||||
// updateData();
|
||||
// loadinitializeData();
|
||||
// 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;
|
||||
}
|
||||
if (!mounted) return;
|
||||
try {
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
@ -116,6 +138,9 @@ class TemplateForexState extends State<TemplateForex> {
|
||||
updateData();
|
||||
loadinitializeData();
|
||||
loadInitialData();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -28,7 +28,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
// GlobalKey<TemplatesListState>();
|
||||
|
||||
final ApiService apiService = ApiService();
|
||||
late Future<List<dynamic>> futureTemplates;
|
||||
Future<List<dynamic>>? futureTemplates;
|
||||
// late Future<List<dynamic>> futureTemplates;
|
||||
|
||||
late Map<String, dynamic> userSingleData;
|
||||
List<dynamic>? apiCountryData;
|
||||
@ -48,9 +49,38 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAuthAndLoadData();
|
||||
// futureTemplates = fetchGetForex();
|
||||
//
|
||||
// futureTemplates.then((users) {
|
||||
// setState(() {
|
||||
// allTemplate = users;
|
||||
// print("AlL tEMPLATESNIT - $allTemplate");
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// 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 {
|
||||
futureTemplates = fetchGetForex();
|
||||
|
||||
futureTemplates.then((users) {
|
||||
futureTemplates?.then((users) {
|
||||
setState(() {
|
||||
allTemplate = users;
|
||||
print("AlL tEMPLATESNIT - $allTemplate");
|
||||
@ -60,16 +90,17 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> refreshData() {
|
||||
Future<List<dynamic>?> refreshData() {
|
||||
print("Calling Refresh Data");
|
||||
|
||||
futureTemplates = fetchGetForex();
|
||||
|
||||
return futureTemplates.then((users) {
|
||||
return futureTemplates!.then((users) {
|
||||
setState(() {
|
||||
allTemplate = users;
|
||||
});
|
||||
@ -82,11 +113,13 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
String? bodyStringColor = await getBodyColor();
|
||||
|
||||
setState(() {
|
||||
layoutColor = layoutString != null
|
||||
layoutColor =
|
||||
layoutString != null
|
||||
? Color(int.parse(layoutString))
|
||||
: Colors.redAccent;
|
||||
|
||||
bodyColor = bodyStringColor != null
|
||||
bodyColor =
|
||||
bodyStringColor != null
|
||||
? Color(int.parse(bodyStringColor))
|
||||
: Colors.white;
|
||||
});
|
||||
@ -95,9 +128,12 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
String formatTemplateName(String input) {
|
||||
return input
|
||||
.split('_') // split by underscore
|
||||
.map((word) => word.isNotEmpty
|
||||
.map(
|
||||
(word) =>
|
||||
word.isNotEmpty
|
||||
? '${word[0].toUpperCase()}${word.substring(1)}'
|
||||
: '')
|
||||
: '',
|
||||
)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
@ -106,7 +142,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
|
||||
try {
|
||||
final List<dynamic> decoded = json.decode(raw);
|
||||
final List<String> values = decoded
|
||||
final List<String> values =
|
||||
decoded
|
||||
.map((e) => e['value'].toString().replaceAll('%', ''))
|
||||
.toList();
|
||||
return values.join(', ');
|
||||
@ -157,7 +194,10 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
}
|
||||
|
||||
Future<void> createTemplateData(
|
||||
Map<String, dynamic> userData, String userId, String newStatus) async {
|
||||
Map<String, dynamic> userData,
|
||||
String userId,
|
||||
String newStatus,
|
||||
) async {
|
||||
final uri = Uri.parse('$apiUrl/api/users/update/$userId');
|
||||
|
||||
final String? token = await getToken();
|
||||
@ -207,8 +247,11 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
}
|
||||
}
|
||||
|
||||
void handleToggleUserStatus(String userId, String currentStatus,
|
||||
Map<String, dynamic> userData) async {
|
||||
void handleToggleUserStatus(
|
||||
String userId,
|
||||
String currentStatus,
|
||||
Map<String, dynamic> userData,
|
||||
) async {
|
||||
print("Toggling user status - $userId (Current: $currentStatus)");
|
||||
|
||||
final String apiUrlData =
|
||||
@ -264,7 +307,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
final lowerQuery = query.toLowerCase();
|
||||
|
||||
setState(() {
|
||||
filteredTemplates = allTemplate.where((user) {
|
||||
filteredTemplates =
|
||||
allTemplate.where((user) {
|
||||
// Match template_name
|
||||
final templateName =
|
||||
(user['template_name'] ?? '').toString().toLowerCase();
|
||||
@ -277,13 +321,20 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
if (placeholderRaw != null && placeholderRaw is String) {
|
||||
try {
|
||||
final List<dynamic> decoded = json.decode(placeholderRaw);
|
||||
final List<String> placeholderValues = decoded
|
||||
.map((e) =>
|
||||
e['value'].toString().replaceAll('%', '').toLowerCase())
|
||||
final List<String> placeholderValues =
|
||||
decoded
|
||||
.map(
|
||||
(e) =>
|
||||
e['value']
|
||||
.toString()
|
||||
.replaceAll('%', '')
|
||||
.toLowerCase(),
|
||||
)
|
||||
.toList();
|
||||
|
||||
matchesPlaceholder =
|
||||
placeholderValues.any((value) => value.contains(lowerQuery));
|
||||
matchesPlaceholder = placeholderValues.any(
|
||||
(value) => value.contains(lowerQuery),
|
||||
);
|
||||
} catch (e) {
|
||||
// ignore invalid placeholder format
|
||||
}
|
||||
@ -298,8 +349,10 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
return ResponsiveBuilder(
|
||||
builder: (context, sizingInfo) {
|
||||
bool isDesktop =
|
||||
sizingInfo.deviceScreenType == DeviceScreenType.desktop;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFf5f5f5),
|
||||
@ -308,11 +361,14 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
appBar: CustomAppBar(isDesktop: isDesktop),
|
||||
drawer: CustomDrawer(isDesktop: false),
|
||||
body: Padding(
|
||||
padding: isDesktop
|
||||
padding:
|
||||
isDesktop
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: MediaQuery.of(context).size.width *
|
||||
horizontal:
|
||||
MediaQuery.of(context).size.width *
|
||||
0.1, // 30% of screen width as horizontal padding
|
||||
vertical: MediaQuery.of(context).size.height *
|
||||
vertical:
|
||||
MediaQuery.of(context).size.height *
|
||||
0, // 5% of screen height as vertical padding
|
||||
)
|
||||
: EdgeInsets.all(0),
|
||||
@ -325,7 +381,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildGroupList(bool isDesktop) {
|
||||
@ -353,7 +410,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
// ? EdgeInsets.all(10.0)
|
||||
// : EdgeInsets.only(left: 20.0, bottom: 20.0, top: 10.0, right: 20.0),
|
||||
// padding: const EdgeInsets.all(10),
|
||||
height: isDesktop
|
||||
height:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.height * 0.98
|
||||
: MediaQuery.of(context).size.height,
|
||||
|
||||
@ -385,9 +443,7 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.23,
|
||||
),
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.23),
|
||||
|
||||
if (isDesktop)
|
||||
Container(
|
||||
@ -399,7 +455,9 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search ...",
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 12, color: Color(0xFF9E9DBD)),
|
||||
fontSize: 12,
|
||||
color: Color(0xFF9E9DBD),
|
||||
),
|
||||
prefixIcon: Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF9E9DBD),
|
||||
@ -411,17 +469,19 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade200, width: 0.5),
|
||||
color: Colors.grey.shade200,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade300, width: 1),
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
),
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
),
|
||||
// SizedBox(width: 16),
|
||||
@ -464,10 +524,7 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
],
|
||||
),
|
||||
|
||||
if (!isDesktop)
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (!isDesktop) SizedBox(height: 5),
|
||||
isDesktop
|
||||
? SizedBox.shrink()
|
||||
: Row(
|
||||
@ -482,7 +539,9 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search ...",
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 12, color: Color(0xFF9E9DBD)),
|
||||
fontSize: 12,
|
||||
color: Color(0xFF9E9DBD),
|
||||
),
|
||||
prefixIcon: Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF9E9DBD),
|
||||
@ -495,17 +554,18 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade200,
|
||||
width: 0.5),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey.shade300, width: 1),
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
),
|
||||
style: GoogleFonts.poppins(fontSize: 12),
|
||||
),
|
||||
),
|
||||
// SizedBox(width: 16),
|
||||
@ -515,6 +575,9 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: futureTemplates,
|
||||
builder: (context, snapshot) {
|
||||
if (futureTemplates == null) {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError ||
|
||||
@ -543,14 +606,17 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey),
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
"Please Create Templates",
|
||||
textAlign: TextAlign.center,
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 16, color: Colors.grey),
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
@ -559,7 +625,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
);
|
||||
}
|
||||
|
||||
List<dynamic> templates = filteredTemplates.isNotEmpty
|
||||
List<dynamic> templates =
|
||||
filteredTemplates.isNotEmpty
|
||||
? filteredTemplates
|
||||
: allTemplate;
|
||||
|
||||
@ -573,25 +640,27 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
|
||||
templates.sort((a, b) {
|
||||
try {
|
||||
DateTime dateA =
|
||||
DateTime.parse(a['created_at'] ?? '2000-01-01');
|
||||
DateTime dateB =
|
||||
DateTime.parse(b['created_at'] ?? '2000-01-01');
|
||||
DateTime dateA = DateTime.parse(
|
||||
a['created_at'] ?? '2000-01-01',
|
||||
);
|
||||
DateTime dateB = DateTime.parse(
|
||||
b['created_at'] ?? '2000-01-01',
|
||||
);
|
||||
return dateB.compareTo(dateA);
|
||||
} catch (e) {
|
||||
return 0; // If parsing fails, consider them equal
|
||||
}
|
||||
});
|
||||
|
||||
List paginatedTemplates = templates
|
||||
List paginatedTemplates =
|
||||
templates
|
||||
.skip(currentPage * itemsPerPage)
|
||||
.take(itemsPerPage)
|
||||
.toList();
|
||||
|
||||
Widget table = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
double minWidth =
|
||||
isDesktop ? constraints.maxWidth : 1300;
|
||||
double minWidth = isDesktop ? constraints.maxWidth : 1300;
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: minWidth),
|
||||
@ -600,7 +669,9 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
columnSpacing: isDesktop ? 24.0 : 16.0,
|
||||
border: TableBorder(
|
||||
horizontalInside: BorderSide(
|
||||
width: 0.5, color: Colors.grey.shade200),
|
||||
width: 0.5,
|
||||
color: Colors.grey.shade200,
|
||||
),
|
||||
),
|
||||
columns: [
|
||||
DataColumn(
|
||||
@ -608,8 +679,10 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
'Template Name',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
// DataColumn(
|
||||
// label: Text(
|
||||
// 'Attributes',
|
||||
@ -622,24 +695,33 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
'Actions',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600),
|
||||
)),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: paginatedTemplates.map((forex) {
|
||||
String forexId = forex['template_id']
|
||||
rows:
|
||||
paginatedTemplates.map((forex) {
|
||||
String forexId =
|
||||
forex['template_id']
|
||||
.toString(); // Get user ID
|
||||
bool isSelected = selectedUserId == forexId;
|
||||
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(
|
||||
Text(
|
||||
// "${forex['template_name'] ?? ''}",
|
||||
formatTemplateName(
|
||||
forex['template_name'] ?? ''),
|
||||
forex['template_name'] ?? '',
|
||||
),
|
||||
// Text("{forex['template_name'] ?? ''}",
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontFamily: "Inter",
|
||||
))),
|
||||
),
|
||||
),
|
||||
),
|
||||
// DataCell(Text(
|
||||
// getPlaceholderNames(forex['placeholder']),
|
||||
// style: TextStyle(
|
||||
@ -656,7 +738,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
child: Image.asset(
|
||||
'assets/images/IconsImg/edit.png',
|
||||
width: 20,
|
||||
height: 15),
|
||||
height: 15,
|
||||
),
|
||||
onTap: () async {
|
||||
// final userId = getUserId(user['user_id']);
|
||||
// final usersData = await getUserDetails(userId);
|
||||
@ -664,7 +747,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
|
||||
// context.go('/template');
|
||||
final templateId = int.tryParse(
|
||||
forex['template_id'].toString());
|
||||
forex['template_id'].toString(),
|
||||
);
|
||||
|
||||
if (templateId != null) {
|
||||
print("templateId -- $templateId");
|
||||
@ -672,16 +756,18 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
.getTemplateFind(templateId);
|
||||
print("ForexId -- $data");
|
||||
|
||||
context.go('/template', extra: {
|
||||
'templateData': data,
|
||||
});
|
||||
context.go(
|
||||
'/template',
|
||||
extra: {'templateData': data},
|
||||
);
|
||||
} else {
|
||||
print("Invalid Forex ID");
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
]);
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
@ -696,7 +782,9 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
return Card(
|
||||
color: Colors.white,
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 6),
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@ -714,16 +802,18 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
Text(
|
||||
// forex['template_name'] ?? 'N/A',
|
||||
formatTemplateName(
|
||||
forex['template_name'] ?? ''),
|
||||
forex['template_name'] ?? '',
|
||||
),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.w700),
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
UserActionsMenu(
|
||||
user: forex,
|
||||
getUserDetails: (id) =>
|
||||
apiService.getSingleUser(id),
|
||||
getUserDetails:
|
||||
(id) => apiService.getSingleUser(id),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -764,7 +854,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: isDesktop
|
||||
child:
|
||||
isDesktop
|
||||
? (searchController.text.isNotEmpty &&
|
||||
filteredTemplates.isEmpty
|
||||
? Center(
|
||||
@ -772,7 +863,8 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
"No matches found",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
color: Colors.grey),
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
@ -786,11 +878,13 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
"No matches found",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
color: Colors.grey),
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: buildMobileCardView(
|
||||
paginatedTemplates)),
|
||||
paginatedTemplates,
|
||||
)),
|
||||
),
|
||||
// Expanded(
|
||||
// child: isDesktop
|
||||
@ -821,9 +915,11 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
]),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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((_) {
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
_popStateListener = html.window.onPopState.listen((event) {
|
||||
if (!_dialogShown && mounted) {
|
||||
_showBackConfirmationDialog();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// initializeData();
|
||||
// loadInitialData();
|
||||
|
||||
// futurePlans.then((plans) {
|
||||
// setState(() {
|
||||
// allPlans = plans;
|
||||
// filteredPlans = plans;
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
}
|
||||
}
|
||||
|
||||
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,13 +409,31 @@ 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(
|
||||
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),
|
||||
@ -356,6 +458,7 @@ class _ListPlansState extends State<ListPlans> {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@ -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,20 +44,48 @@ class _PolicyListState extends State<PolicyList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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) {
|
||||
futurePolicy?.then((object) {
|
||||
setState(() {
|
||||
allPolicy = object;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
fetchPolicy();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -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,9 +48,37 @@ class TravellerListState extends State<TravellerList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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) {
|
||||
futureTraveller?.then((object) {
|
||||
setState(() {
|
||||
allTraveller = object;
|
||||
});
|
||||
@ -58,8 +87,9 @@ class TravellerListState extends State<TravellerList> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
} catch (e) {
|
||||
print("group : $e");
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -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,14 +177,16 @@ class TravellerListState extends State<TravellerList> {
|
||||
final lowerQuery = query.toLowerCase().trim();
|
||||
|
||||
setState(() {
|
||||
filteredTraveller = allTraveller.where((object) {
|
||||
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";
|
||||
final isActiveStatus =
|
||||
object['is_active'] == "1" ? "active" : "inactive";
|
||||
|
||||
return travellerId.contains(lowerQuery) ||
|
||||
firstName.contains(lowerQuery) ||
|
||||
@ -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,8 +340,161 @@ 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";
|
||||
|
||||
apiCountryData = null;
|
||||
apiUserData = null;
|
||||
apiCostData = null;
|
||||
apiRoleData = null;
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
/// ✅ 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";
|
||||
|
||||
@ -358,7 +513,8 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
|
||||
// Initialize controllers for each field
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// if (!mounted) return;
|
||||
// final wasReloaded = html.window.localStorage['reloaded'] == 'true';
|
||||
//
|
||||
// if (wasReloaded) {
|
||||
@ -405,11 +561,17 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
fetchUsers();
|
||||
fetchRoles();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isCheckingToken = false;
|
||||
});
|
||||
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchCountries() async {
|
||||
@ -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,6 +46,31 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// futureUsers = fetchUsers();
|
||||
//
|
||||
// futureUsers.then((users) {
|
||||
// setState(() {
|
||||
// allUsers = users;
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
_checkAuthAndLoadData();
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -53,13 +78,13 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
allUsers = users;
|
||||
});
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchCountryList();
|
||||
loadInitialData();
|
||||
});
|
||||
|
||||
// futurePlans = fetchPlans();
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// fetchCountryList();
|
||||
// loadInitialData();
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
void loadInitialData() async {
|
||||
@ -195,7 +220,6 @@ class _UserListScreenState extends State<UserListScreen> {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
print("Error response: $errorMsg");
|
||||
throw Exception("Authentication failed: $errorMsg");
|
||||
}
|
||||
} 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,9 +295,26 @@ 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(
|
||||
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,
|
||||
@ -331,7 +348,11 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
width: 130, //130
|
||||
height: 80, //80
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
errorBuilder: (
|
||||
context,
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
return const CircleAvatar(
|
||||
radius: 20,
|
||||
child: Icon(
|
||||
@ -372,7 +393,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
'/StatusDashboard',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.dashboard,
|
||||
isSelected:
|
||||
selectedTab == TabSelection.dashboard,
|
||||
icon: Icons.dashboard,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
@ -388,7 +410,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
'/listAllPlan',
|
||||
),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.allTrips,
|
||||
isSelected:
|
||||
selectedTab == TabSelection.allTrips,
|
||||
icon: Icons.format_list_bulleted_rounded,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
@ -407,7 +430,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
icon: Icons.shopping_bag_outlined,
|
||||
// icon: Icons.request_page_outlined,
|
||||
),
|
||||
if (userData?["role"] != "Travel Agent") // for others
|
||||
if (userData?["role"] !=
|
||||
"Travel Agent") // for others
|
||||
buildNavItem(
|
||||
"My Trips",
|
||||
() => handleTabChange(
|
||||
@ -454,7 +478,10 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
(context) => PopupMenuButton<String>(
|
||||
color: Colors.white,
|
||||
padding: EdgeInsets.zero,
|
||||
offset: const Offset(0, 50), // 👈 shift it 50 pixels down
|
||||
offset: const Offset(
|
||||
0,
|
||||
50,
|
||||
), // 👈 shift it 50 pixels down
|
||||
onSelected: (String value) {
|
||||
switch (value) {
|
||||
case '/OrganizationSettings':
|
||||
@ -509,7 +536,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
menuItems
|
||||
.where(
|
||||
(item) =>
|
||||
item['value'] == '/CreateUserDetails' ||
|
||||
item['value'] ==
|
||||
'/CreateUserDetails' ||
|
||||
item['value'] == '/logout',
|
||||
)
|
||||
.toList();
|
||||
@ -617,6 +645,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
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