travel policy
This commit is contained in:
parent
8de950586a
commit
b625692dad
@ -13,6 +13,7 @@ import 'package:flutter_quill/flutter_quill_internal.dart';
|
||||
import 'package:flutter_quill/quill_delta.dart';
|
||||
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
|
||||
import 'package:frontend/Screens/myTemplates/quill_delta_sample.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:responsive_builder/responsive_builder.dart';
|
||||
@ -24,6 +25,14 @@ import '../../utils/auth_utils.dart';
|
||||
import '../../widgets/custom_user_travel.dart';
|
||||
|
||||
class Template extends StatefulWidget {
|
||||
final Map<String, dynamic>? templateData;
|
||||
|
||||
const Template({super.key, required this.templateData});
|
||||
|
||||
static Template fromState(GoRouterState state) {
|
||||
return Template(templateData: state.extra as Map<String, dynamic>?);
|
||||
}
|
||||
|
||||
@override
|
||||
TemplateState createState() => TemplateState();
|
||||
}
|
||||
@ -32,25 +41,53 @@ class TemplateState extends State<Template> {
|
||||
final ApiService apiService = ApiService();
|
||||
|
||||
final FocusNode _editorFocusNode = FocusNode();
|
||||
final ScrollController _editorScrollController = ScrollController();
|
||||
final QuillController _controller = QuillController.basic();
|
||||
// final ScrollController _editorScrollController = ScrollController();
|
||||
// final QuillController _controller = QuillController.basic();
|
||||
Color layoutColor = Colors.redAccent;
|
||||
Color bodyColor = Colors.white;
|
||||
final Map<String, TextEditingController> controllers = {};
|
||||
List<String> dataHeader = ["subject"];
|
||||
|
||||
Map<String, dynamic> get TemplateData {
|
||||
final data = {
|
||||
// "org_id": orgId;
|
||||
"template_name": controllers["templateName"]?.text,
|
||||
"subject": controllers["subject"]?.text,
|
||||
"body_html": controllers["bodyData"]?.text,
|
||||
"placeholder": [],
|
||||
// "created_by": userId
|
||||
};
|
||||
|
||||
// Only add group_id if it's an edit operation
|
||||
// if (widget.templateData != null && widget.templateData!.containsKey('group_id')) {
|
||||
// data["template_id"] = templateData;
|
||||
// }
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
for (var field in dataHeader) {
|
||||
controllers[field] = TextEditingController();
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_editorFocusNode.requestFocus(); // ✅ Ensure focus is requested
|
||||
});
|
||||
// _controller.document = Document.fromJson(kQuillDefaultSample);
|
||||
// _controller.readOnly = false;
|
||||
updateData();
|
||||
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_editorScrollController.dispose();
|
||||
// controllers.dispose();
|
||||
// _editorScrollController.dispose();
|
||||
_editorFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@ -70,6 +107,27 @@ class TemplateState extends State<Template> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateData() async {
|
||||
// Ensure apiselectedUser is not null before printing
|
||||
if (widget.templateData != null) {
|
||||
print("API Selected User Has Data - ${widget.templateData}");
|
||||
print(
|
||||
"API Selected User Has - ${widget.templateData?["templateData"]?["subject"]}");
|
||||
setState(() {
|
||||
// ✅ Wrap in setState to update the UI
|
||||
controllers["subject"]?.text =
|
||||
widget.templateData?["templateData"]?["subject"] ?? "";
|
||||
|
||||
// if (widget.group?["international_policy_id"] != null) {
|
||||
// selectedInternational =
|
||||
// widget.group!["international_policy_id"].toString();
|
||||
// }
|
||||
});
|
||||
} else {
|
||||
print("API Selected User Has Data - No data available yet");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveBuilder(builder: (context, sizingInfo) {
|
||||
@ -146,7 +204,7 @@ class TemplateState extends State<Template> {
|
||||
height: 40,
|
||||
child: TextField(
|
||||
style: GoogleFonts.poppins(fontSize: 12, color: Colors.black),
|
||||
// controller: _controller[""],
|
||||
controller: controllers["subject"],
|
||||
onChanged: (value) {
|
||||
// _clearError("local_id_num");
|
||||
},
|
||||
@ -181,99 +239,99 @@ class TemplateState extends State<Template> {
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ✅ Modern toolbar
|
||||
QuillSimpleToolbar(
|
||||
controller: _controller,
|
||||
config: QuillSimpleToolbarConfig(
|
||||
embedButtons: FlutterQuillEmbeds.toolbarButtons(),
|
||||
showClipboardPaste: true,
|
||||
customButtons: [
|
||||
QuillToolbarCustomButtonOptions(
|
||||
icon: const Icon(Icons.add_alarm_rounded),
|
||||
onPressed: () {
|
||||
_controller.document.insert(
|
||||
_controller.selection.extentOffset,
|
||||
TimeStampEmbed(
|
||||
DateTime.now().toString(),
|
||||
),
|
||||
);
|
||||
|
||||
_controller.updateSelection(
|
||||
TextSelection.collapsed(
|
||||
offset: _controller.selection.extentOffset + 1,
|
||||
),
|
||||
ChangeSource.local,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
buttonOptions: QuillSimpleToolbarButtonOptions(
|
||||
base: QuillToolbarBaseButtonOptions(
|
||||
afterButtonPressed: () {
|
||||
final isDesktop = {
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.macOS
|
||||
}.contains(defaultTargetPlatform);
|
||||
if (isDesktop) {
|
||||
_editorFocusNode.requestFocus();
|
||||
}
|
||||
},
|
||||
),
|
||||
linkStyle: QuillToolbarLinkStyleButtonOptions(
|
||||
validateLink: (link) {
|
||||
// Treats all links as valid. When launching the URL,
|
||||
// `https://` is prefixed if the link is incomplete (e.g., `google.com` → `https://google.com`)
|
||||
// however this happens only within the editor.
|
||||
return true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ✅ Modern editor
|
||||
Container(
|
||||
height: 300,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: QuillEditor.basic(
|
||||
focusNode: _editorFocusNode,
|
||||
scrollController: _editorScrollController,
|
||||
controller: _controller,
|
||||
// readOnly: true,
|
||||
config: QuillEditorConfig(
|
||||
requestKeyboardFocusOnCheckListChanged: false,
|
||||
// readOnlyMouseCursor: SystemMouseCursors.text,
|
||||
enableScribble: true,
|
||||
|
||||
padding: const EdgeInsets.all(8),
|
||||
placeholder: 'Type something...',
|
||||
embedBuilders: [
|
||||
...FlutterQuillEmbeds.editorBuilders(
|
||||
imageEmbedConfig: QuillEditorImageEmbedConfig(
|
||||
imageProviderBuilder: (context, imageUrl) {
|
||||
// https://pub.dev/packages/flutter_quill_extensions#-image-assets
|
||||
if (imageUrl.startsWith('assets/')) {
|
||||
return AssetImage(imageUrl);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
videoEmbedConfig: QuillEditorVideoEmbedConfig(
|
||||
customVideoBuilder: (videoUrl, readOnly) {
|
||||
// To load YouTube videos https://github.com/singerdmx/flutter-quill/releases/tag/v10.8.0
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
TimeStampEmbedBuilder(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// QuillSimpleToolbar(
|
||||
// controller: _controller,
|
||||
// config: QuillSimpleToolbarConfig(
|
||||
// embedButtons: FlutterQuillEmbeds.toolbarButtons(),
|
||||
// showClipboardPaste: true,
|
||||
// customButtons: [
|
||||
// QuillToolbarCustomButtonOptions(
|
||||
// icon: const Icon(Icons.add_alarm_rounded),
|
||||
// onPressed: () {
|
||||
// _controller.document.insert(
|
||||
// _controller.selection.extentOffset,
|
||||
// TimeStampEmbed(
|
||||
// DateTime.now().toString(),
|
||||
// ),
|
||||
// );
|
||||
//
|
||||
// _controller.updateSelection(
|
||||
// TextSelection.collapsed(
|
||||
// offset: _controller.selection.extentOffset + 1,
|
||||
// ),
|
||||
// ChangeSource.local,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// buttonOptions: QuillSimpleToolbarButtonOptions(
|
||||
// base: QuillToolbarBaseButtonOptions(
|
||||
// afterButtonPressed: () {
|
||||
// final isDesktop = {
|
||||
// TargetPlatform.linux,
|
||||
// TargetPlatform.windows,
|
||||
// TargetPlatform.macOS
|
||||
// }.contains(defaultTargetPlatform);
|
||||
// if (isDesktop) {
|
||||
// _editorFocusNode.requestFocus();
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// linkStyle: QuillToolbarLinkStyleButtonOptions(
|
||||
// validateLink: (link) {
|
||||
// // Treats all links as valid. When launching the URL,
|
||||
// // `https://` is prefixed if the link is incomplete (e.g., `google.com` → `https://google.com`)
|
||||
// // however this happens only within the editor.
|
||||
// return true;
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
//
|
||||
// // ✅ Modern editor
|
||||
// Container(
|
||||
// height: 300,
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(color: Colors.grey),
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// ),
|
||||
// child: QuillEditor.basic(
|
||||
// focusNode: _editorFocusNode,
|
||||
// scrollController: _editorScrollController,
|
||||
// controller: _controller,
|
||||
// // readOnly: true,
|
||||
// config: QuillEditorConfig(
|
||||
// requestKeyboardFocusOnCheckListChanged: false,
|
||||
// // readOnlyMouseCursor: SystemMouseCursors.text,
|
||||
// enableScribble: true,
|
||||
//
|
||||
// padding: const EdgeInsets.all(8),
|
||||
// placeholder: 'Type something...',
|
||||
// embedBuilders: [
|
||||
// ...FlutterQuillEmbeds.editorBuilders(
|
||||
// imageEmbedConfig: QuillEditorImageEmbedConfig(
|
||||
// imageProviderBuilder: (context, imageUrl) {
|
||||
// // https://pub.dev/packages/flutter_quill_extensions#-image-assets
|
||||
// if (imageUrl.startsWith('assets/')) {
|
||||
// return AssetImage(imageUrl);
|
||||
// }
|
||||
// return null;
|
||||
// },
|
||||
// ),
|
||||
// videoEmbedConfig: QuillEditorVideoEmbedConfig(
|
||||
// customVideoBuilder: (videoUrl, readOnly) {
|
||||
// // To load YouTube videos https://github.com/singerdmx/flutter-quill/releases/tag/v10.8.0
|
||||
// return null;
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// TimeStampEmbedBuilder(),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -425,42 +425,42 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
),
|
||||
),
|
||||
// SizedBox(width: 16),
|
||||
Spacer(),
|
||||
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF114D8B),
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: Color(0xFF114D8B),
|
||||
disabledForegroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side:
|
||||
BorderSide(color: Color(0xFF114D8B), width: 2),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 20, vertical: 12),
|
||||
),
|
||||
onPressed: () async {},
|
||||
child: Row(
|
||||
mainAxisSize:
|
||||
MainAxisSize.min, // Ensures content fits nicely
|
||||
children: [
|
||||
Text(
|
||||
"Add Templates",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: isDesktop ? 13 : 11,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8), // spacing between icon and text
|
||||
Icon(
|
||||
Icons.add_circle_outline_rounded,
|
||||
size: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Spacer(),
|
||||
//
|
||||
// ElevatedButton(
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: Color(0xFF114D8B),
|
||||
// foregroundColor: Colors.white,
|
||||
// disabledBackgroundColor: Color(0xFF114D8B),
|
||||
// disabledForegroundColor: Colors.white,
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// side:
|
||||
// BorderSide(color: Color(0xFF114D8B), width: 2),
|
||||
// ),
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: 20, vertical: 12),
|
||||
// ),
|
||||
// onPressed: () async {},
|
||||
// child: Row(
|
||||
// mainAxisSize:
|
||||
// MainAxisSize.min, // Ensures content fits nicely
|
||||
// children: [
|
||||
// Text(
|
||||
// "Add Templates",
|
||||
// style: GoogleFonts.poppins(
|
||||
// fontSize: isDesktop ? 13 : 11,
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(width: 8), // spacing between icon and text
|
||||
// Icon(
|
||||
// Icons.add_circle_outline_rounded,
|
||||
// size: 15,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
|
||||
@ -661,15 +661,20 @@ class TemplatesListState extends State<TemplatesList> {
|
||||
// final userId = getUserId(user['user_id']);
|
||||
// final usersData = await getUserDetails(userId);
|
||||
//
|
||||
|
||||
// context.go('/template');
|
||||
final templateId = int.tryParse(
|
||||
forex['forex_perdiem_id']
|
||||
.toString());
|
||||
forex['template_id'].toString());
|
||||
|
||||
if (templateId != null) {
|
||||
print("templateId -- $templateId");
|
||||
final data = await apiService
|
||||
.getTemplateFind(templateId);
|
||||
print("ForexId -- $data");
|
||||
|
||||
context.go('/template', extra: {
|
||||
'templateData': data,
|
||||
});
|
||||
} else {
|
||||
print("Invalid Forex ID");
|
||||
}
|
||||
|
||||
@ -581,27 +581,64 @@ class _PolicyState extends State<Policy> {
|
||||
),
|
||||
],
|
||||
isDesktop
|
||||
? Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
_buildPolicyCategoryList(isDesktop),
|
||||
_buildPolicyCategory(isDesktop),
|
||||
],
|
||||
? Container(
|
||||
// color: Colors.yellow.shade50,
|
||||
height: MediaQuery.of(context).size.height * 0.54,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
_buildPolicyOrdering(isDesktop),
|
||||
_buildPolicyCategory(isDesktop),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
_buildPolicyCategoryList(isDesktop),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Expanded(
|
||||
child: Column(
|
||||
child: Row(
|
||||
children: [
|
||||
_buildPolicyCategoryList(isDesktop),
|
||||
// _buildPolicyOrdering(isDesktop),
|
||||
_buildPolicyCategory(isDesktop),
|
||||
],
|
||||
),
|
||||
),
|
||||
// isDesktop
|
||||
// ? Expanded(
|
||||
// child: Row(
|
||||
// children: [
|
||||
// _buildPolicyCategory(isDesktop),
|
||||
// _buildPolicyCategoryList(isDesktop),
|
||||
// ],
|
||||
// ),
|
||||
// )
|
||||
// : Expanded(
|
||||
// child: Column(
|
||||
// children: [
|
||||
// _buildPolicyCategoryList(isDesktop),
|
||||
// _buildPolicyCategory(isDesktop),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget _buildServiceSelect(bool isDesktop){
|
||||
// return [];
|
||||
// }
|
||||
|
||||
Widget _buildPolicyNameField(bool isDesktop) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -665,7 +702,8 @@ class _PolicyState extends State<Policy> {
|
||||
|
||||
Widget _buildPolicyCategoryList(bool isDesktop) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
// color: Colors.white,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
// color: Colors.blueGrey.shade200,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.15 : null,
|
||||
child: isDesktop
|
||||
@ -685,6 +723,129 @@ class _PolicyState extends State<Policy> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPolicyOrdering(bool isDesktop) {
|
||||
return Container(
|
||||
// height: 50,
|
||||
// color: Colors.white,
|
||||
// color: Colors.blueGrey.shade200,
|
||||
padding: isDesktop ? const EdgeInsets.only(left: 35) : null,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.62 : null,
|
||||
// width: isDesktop ? MediaQuery.of(context).size.width * 0.75 : null,
|
||||
child: isDesktop
|
||||
? Container(
|
||||
// color: Colors.amber,
|
||||
child: Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [_buildPolicyServiceOrdering(isDesktop)],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
// color: Colors.amber,
|
||||
child: Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [_buildPolicyServiceOrdering(isDesktop)],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPolicyServiceOrdering(bool isDesktop) {
|
||||
if (ServicesChoosed == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
// Sort services by 'order'
|
||||
ServicesChoosed!
|
||||
.sort((a, b) => (a['order'] ?? 0).compareTo(b['order'] ?? 0));
|
||||
|
||||
List<String> services =
|
||||
ServicesChoosed!.map((service) => service['name'].toString()).toList();
|
||||
|
||||
return Expanded(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Flex(
|
||||
direction: Axis.horizontal,
|
||||
children: services.asMap().entries.map((entry) {
|
||||
int index = entry.key + 1;
|
||||
String service = entry.value;
|
||||
bool isSelected = selectedServiceIndex.value == index.toString();
|
||||
|
||||
return SizedBox(
|
||||
// width: isDesktop ? 140 : null,
|
||||
height: isDesktop
|
||||
? max((MediaQuery.of(context).size.height * 0.075), 10)
|
||||
: 45,
|
||||
|
||||
// max((MediaQuery.of(context).size.height * 0.09), 10)
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
print("Selected Services - $service - $index");
|
||||
setState(() {
|
||||
selectedServiceIndex.value = index.toString();
|
||||
selectedService = service;
|
||||
|
||||
if (selectedService == "Flight" ||
|
||||
selectedService == "Train") {
|
||||
showClass = true;
|
||||
showCost = true;
|
||||
int serviceCode = selectedService == "Flight" ? 1 : 2;
|
||||
policyCriteriaKey.currentState?.fetchTrainFlightClass();
|
||||
} else if (selectedService == "Accommodation") {
|
||||
showClass = true;
|
||||
showCost = false;
|
||||
} else {
|
||||
showClass = false;
|
||||
showCost = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: isDesktop
|
||||
? const EdgeInsets.all(8)
|
||||
: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 3),
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
service,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? const Color(0xFF114D8B)
|
||||
: Colors.black87,
|
||||
fontSize: 13,
|
||||
fontWeight:
|
||||
isSelected ? FontWeight.bold : FontWeight.w100,
|
||||
decoration: TextDecoration
|
||||
.none, // remove built-in underline
|
||||
),
|
||||
),
|
||||
if (isSelected)
|
||||
const SizedBox(
|
||||
height: 1), // spacing between text and underline
|
||||
if (isSelected)
|
||||
Container(
|
||||
height: 2,
|
||||
width: 30, // or based on text width
|
||||
color: const Color(0xFF114D8B),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPolicySubCategoryList(bool isDesktop) {
|
||||
// List<String> services = [
|
||||
// "Flight",
|
||||
@ -727,21 +888,21 @@ class _PolicyState extends State<Policy> {
|
||||
print("Selected Services - $service - $index");
|
||||
setState(() {
|
||||
selectedServiceIndex.value = index.toString();
|
||||
selectedService = service;
|
||||
|
||||
if (selectedService == "Flight" ||
|
||||
selectedService == "Train") {
|
||||
showClass = true;
|
||||
showCost = true;
|
||||
int serviceCode = selectedService == "Flight" ? 1 : 2;
|
||||
policyCriteriaKey.currentState?.fetchTrainFlightClass();
|
||||
} else if (selectedService == "Accommodation") {
|
||||
showClass = true;
|
||||
showCost = false;
|
||||
} else {
|
||||
showClass = false;
|
||||
showCost = false;
|
||||
}
|
||||
// selectedService = service;
|
||||
//
|
||||
// if (selectedService == "Flight" ||
|
||||
// selectedService == "Train") {
|
||||
// showClass = true;
|
||||
// showCost = true;
|
||||
// int serviceCode = selectedService == "Flight" ? 1 : 2;
|
||||
// policyCriteriaKey.currentState?.fetchTrainFlightClass();
|
||||
// } else if (selectedService == "Accommodation") {
|
||||
// showClass = true;
|
||||
// showCost = false;
|
||||
// } else {
|
||||
// showClass = false;
|
||||
// showCost = false;
|
||||
// }
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
@ -785,31 +946,30 @@ class _PolicyState extends State<Policy> {
|
||||
}
|
||||
|
||||
Widget _buildPolicyCategory(bool isDesktop) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
// color: Colors.brown.shade100,
|
||||
// color: Colors.white60,
|
||||
child: PolicyCriteria(
|
||||
key: policyCriteriaKey,
|
||||
isDesktop: isDesktop,
|
||||
isClass: showClass,
|
||||
isCost: showCost,
|
||||
selectedTabNotifier: selectedServiceIndex,
|
||||
selectedService: selectedService,
|
||||
userId: userId,
|
||||
onPolicyDataChanged: (List<Map<String, dynamic>>? policyData) {
|
||||
print("🟢 policyData received from child: $policyData");
|
||||
return Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
// color: Colors.brown.shade100,
|
||||
// child: Text("data"),
|
||||
// color: Colors.white60,
|
||||
child: PolicyCriteria(
|
||||
key: policyCriteriaKey,
|
||||
isDesktop: isDesktop,
|
||||
isClass: showClass,
|
||||
isCost: showCost,
|
||||
selectedTabNotifier: selectedServiceIndex,
|
||||
selectedService: selectedService,
|
||||
userId: userId,
|
||||
onPolicyDataChanged: (List<Map<String, dynamic>>? policyData) {
|
||||
print("🟢 policyData received from child: $policyData");
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setState(() {
|
||||
policy_details = policyData;
|
||||
_clearError("policy_details");
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setState(() {
|
||||
policy_details = policyData;
|
||||
_clearError("policy_details");
|
||||
});
|
||||
},
|
||||
)),
|
||||
);
|
||||
});
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
List<Widget> _buildTripType(bool isDesktop) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ import 'package:shared_preferences/shared_preferences.dart'; // don't forget
|
||||
import '../services/apiService.dart';
|
||||
import '../utils/auth_utils.dart';
|
||||
|
||||
enum TabSelection { allTrips, myTrips, myApprovals, allMenu }
|
||||
enum TabSelection { allTrips, myTrips, myApprovals, allMenu, dashboard }
|
||||
|
||||
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
final bool isDesktop;
|
||||
@ -56,7 +56,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
});
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin") {
|
||||
selectedTab = TabSelection.allTrips;
|
||||
selectedTab = TabSelection.dashboard;
|
||||
// selectedTab = TabSelection.allTrips;
|
||||
} else {
|
||||
selectedTab = TabSelection.myTrips;
|
||||
}
|
||||
@ -196,6 +197,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
selectedTab = TabSelection.myTrips;
|
||||
} else if (location.contains('/ApprovalList')) {
|
||||
selectedTab = TabSelection.myApprovals;
|
||||
} else if (location.contains('/StatusDashboard')) {
|
||||
selectedTab = TabSelection.dashboard;
|
||||
} else {
|
||||
selectedTab = TabSelection.allMenu;
|
||||
}
|
||||
@ -262,6 +265,20 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
"Dashboard",
|
||||
() => handleTabChange(
|
||||
TabSelection.dashboard, '/StatusDashboard'),
|
||||
layoutColor!,
|
||||
isSelected: selectedTab == TabSelection.dashboard,
|
||||
icon: Icons.dashboard,
|
||||
// icon: Icons.insights_outlined,
|
||||
),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
const SizedBox(width: 20),
|
||||
if (userData?["role"] == "Org Admin" ||
|
||||
userData?["role"] == "Travel Admin")
|
||||
buildNavItem(
|
||||
@ -352,8 +369,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
// context.go('/templateList');
|
||||
// case '/template':
|
||||
// context.go('/template');
|
||||
case '/StatusDashboard':
|
||||
context.go('/StatusDashboard');
|
||||
|
||||
case '/CreateUserDetails':
|
||||
context.go(
|
||||
"/CreateUserDetails",
|
||||
@ -481,11 +497,7 @@ final List<Map<String, dynamic>> menuItems = [
|
||||
'icon': Icons.manage_accounts,
|
||||
'label': 'User Management'
|
||||
},
|
||||
{
|
||||
'value': '/StatusDashboard',
|
||||
'icon': Icons.dashboard_sharp,
|
||||
'label': 'Status Dashboard'
|
||||
},
|
||||
|
||||
// {'value': '/group', 'icon': Icons.group, 'label': 'Group'},
|
||||
// {'value': '/department', 'icon': Icons.group, 'label': 'Department'},
|
||||
// {'value': '/PolicyList', 'icon': Icons.policy, 'label': 'Policy'},
|
||||
|
||||
@ -123,7 +123,10 @@ final GoRouter router = GoRouter(
|
||||
),
|
||||
GoRoute(
|
||||
path: '/template',
|
||||
builder: (context, state) => Template(),
|
||||
// builder: (context, state) => Template(),
|
||||
pageBuilder: (context, state) => MaterialPage(
|
||||
child: Template.fromState(state),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/approvallist',
|
||||
|
||||
@ -896,7 +896,7 @@ class ApiService {
|
||||
throw Exception('Token not found. Please log in.');
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
final response = await http.put(
|
||||
Uri.parse(apiUrldata),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
@ -911,19 +911,26 @@ class ApiService {
|
||||
// print(data.runtimeType);
|
||||
// print(data);
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! List) {
|
||||
// if (!data.containsKey('data') || data['data'] is! List) {
|
||||
// throw Exception(
|
||||
// "Invalid response format: 'data' field is missing or not a List");
|
||||
// }
|
||||
//
|
||||
// final List<Map<String, dynamic>> listData =
|
||||
// List<Map<String, dynamic>>.from(data['data']);
|
||||
//
|
||||
// if (listData.isEmpty) {
|
||||
// throw Exception("No department found with ID $id");
|
||||
// }
|
||||
//
|
||||
// return listData[0];
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
throw Exception(
|
||||
"Invalid response format: 'data' field is missing or not a List");
|
||||
"Invalid response format: 'data' field is missing or not a Map");
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
List<Map<String, dynamic>>.from(data['data']);
|
||||
|
||||
if (listData.isEmpty) {
|
||||
throw Exception("No department found with ID $id");
|
||||
}
|
||||
|
||||
return listData[0];
|
||||
return Map<String, dynamic>.from(data['data']);
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
@ -997,7 +1004,6 @@ class ApiService {
|
||||
false; // Default to false if dismissed
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> getCostCenterDetailsFind(int id) async {
|
||||
final String apiUrldata = '$apiUrl/api/findCostCenter?cost_center_id=$id';
|
||||
|
||||
@ -1028,7 +1034,7 @@ class ApiService {
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> listData =
|
||||
List<Map<String, dynamic>>.from(data['data']);
|
||||
List<Map<String, dynamic>>.from(data['data']);
|
||||
|
||||
if (listData.isEmpty) {
|
||||
throw Exception("No CostCenter found with ID $id");
|
||||
@ -1042,5 +1048,4 @@ class ApiService {
|
||||
throw Exception('Failed to load CostCenter details');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user