diff --git a/lib/models/concession_request_model/concession_request_model.dart b/lib/models/concession_request_model/concession_request_model.dart index 8d3b35e5..7db9f67c 100644 --- a/lib/models/concession_request_model/concession_request_model.dart +++ b/lib/models/concession_request_model/concession_request_model.dart @@ -6,7 +6,7 @@ part 'concession_request_model.g.dart'; @JsonSerializable() class ConcessionRequestModel { @JsonKey(name: "passNum") - int? passNum; + final String? passNum; @JsonKey(name: "status") final String status; @JsonKey(name: "statusMessage") diff --git a/lib/models/concession_request_model/concession_request_model.g.dart b/lib/models/concession_request_model/concession_request_model.g.dart index 54694a39..cb898cf4 100644 --- a/lib/models/concession_request_model/concession_request_model.g.dart +++ b/lib/models/concession_request_model/concession_request_model.g.dart @@ -9,7 +9,7 @@ part of 'concession_request_model.dart'; ConcessionRequestModel _$ConcessionRequestModelFromJson( Map json) => ConcessionRequestModel( - passNum: json['passNum'] as int?, + passNum: json['passNum'] as String?, status: json['status'] as String, statusMessage: json['statusMessage'] as String, // time: json['time'] as Timestamp, diff --git a/lib/new_ui/screens/railway_screen/railway_screen.dart b/lib/new_ui/screens/railway_screen/railway_screen.dart index 51359345..2d6a9151 100644 --- a/lib/new_ui/screens/railway_screen/railway_screen.dart +++ b/lib/new_ui/screens/railway_screen/railway_screen.dart @@ -9,6 +9,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:image_picker/image_picker.dart'; import 'package:intl/intl.dart'; import 'package:tsec_app/models/concession_details_model/concession_details_model.dart'; +import 'package:tsec_app/models/concession_request_model/concession_request_model.dart'; // import 'package:tsec_app/models/concession_request_model/concession_request_model.dart'; import 'package:tsec_app/models/student_model/student_model.dart'; import 'package:tsec_app/new_ui/screens/railway_screen/railwayform.dart'; @@ -17,6 +18,7 @@ import 'package:tsec_app/new_ui/screens/railway_screen/widgets/railway_dropdown_ import 'package:tsec_app/new_ui/screens/railway_screen/widgets/railway_dropdown_field.dart'; import 'package:tsec_app/provider/auth_provider.dart'; import 'package:tsec_app/provider/concession_provider.dart'; +import 'package:tsec_app/provider/concession_request_provider.dart'; import 'package:tsec_app/provider/railway_concession_provider.dart'; import 'package:tsec_app/new_ui/screens/railway_screen/widgets/railway_text_field.dart'; import 'package:tsec_app/utils/railway_enum.dart'; @@ -429,7 +431,8 @@ class _RailwayConcessionScreenState Size size = MediaQuery.of(context).size; bool editMode = ref.watch(railwayConcessionOpenProvider); ConcessionDetailsModel? concessionDetails = ref.watch(concessionDetailsProvider); - + ConcessionRequestModel? concessionRequestData = ref.watch(concessionRequestDetailProvider); + print(concessionRequestData.toString()); String formattedDate = lastPassIssued != null ? DateFormat('dd/MM/yyyy').format(lastPassIssued!) : ''; @@ -475,7 +478,7 @@ class _RailwayConcessionScreenState SizedBox( height: 15, ), - if (lastPassIssued != null) + if (1==1) Container( width: size.width * 0.8, child: Column( @@ -502,7 +505,7 @@ class _RailwayConcessionScreenState crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "Certificate Num: Z####", + "Certificate Num: ${concessionRequestData!=null?concessionRequestData.passNum:"not assigned"}", style: TextStyle(fontSize: 16, color: Colors.white), ), SizedBox( diff --git a/lib/provider/auth_provider.dart b/lib/provider/auth_provider.dart index 1d496772..551d72fc 100644 --- a/lib/provider/auth_provider.dart +++ b/lib/provider/auth_provider.dart @@ -11,6 +11,7 @@ import 'package:tsec_app/models/notification_model/notification_model.dart'; import 'package:tsec_app/models/student_model/student_model.dart'; import 'package:tsec_app/models/user_model/user_model.dart'; import 'package:tsec_app/provider/concession_provider.dart'; +import 'package:tsec_app/provider/concession_request_provider.dart'; import 'package:tsec_app/provider/firebase_provider.dart'; import 'package:tsec_app/provider/notes_provider.dart'; import 'package:tsec_app/provider/notification_provider.dart'; @@ -123,6 +124,7 @@ class AuthProvider extends StateNotifier { .watch(authProvider.notifier) .updateStudentTimeTableData(userModel.studentModel, ref); await ref.watch(concessionProvider.notifier).getConcessionData(); + await ref.watch(concessionRequestProvider.notifier).getConcessionRequestData(); } await ref.watch(subjectsProvider.notifier).fetchSubjects(); await ref.watch(authProvider.notifier).fetchProfilePic(); diff --git a/lib/provider/concession_provider.dart b/lib/provider/concession_provider.dart index 7683c66c..19a0752b 100644 --- a/lib/provider/concession_provider.dart +++ b/lib/provider/concession_provider.dart @@ -77,4 +77,5 @@ class ConcessionProvider extends StateNotifier { // debugPrint("concession: ${concessionDetailsData?.firstName}"); _ref.read(concessionDetailsProvider.notifier).state = concessionDetailsData; } + } diff --git a/lib/provider/concession_request_provider.dart b/lib/provider/concession_request_provider.dart new file mode 100644 index 00000000..94dfe72d --- /dev/null +++ b/lib/provider/concession_request_provider.dart @@ -0,0 +1,42 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:tsec_app/models/concession_request_model/concession_request_model.dart'; +import 'package:tsec_app/services/concession_service.dart'; + +final concessionRequestDetailProvider = StateProvider((ref) { + return null; +}); + + +final concessionRequestProvider = StateNotifierProvider((ref) { + return ConcessionRequestProvider( + concessionService: ref.watch(concessionServiceProvider), ref: ref); +}); + + + +class ConcessionRequestProvider extends StateNotifier { + final ConcessionService _concessionService; + final Ref _ref; + + ConcessionRequestProvider({required ConcessionService concessionService, required Ref ref}) + : _concessionService = concessionService, + _ref = ref, + super(false); + + Future getConcessionRequestData() async { + try { + ConcessionRequestModel? concessionRequestDetail = + await _concessionService.getConcessionRequest(); + + _ref.read(concessionRequestDetailProvider.notifier).state = concessionRequestDetail; + + + } catch (e) { + print("Error fetching concession request detail data: $e"); + // Handle error here + } + } +} diff --git a/lib/services/concession_service.dart b/lib/services/concession_service.dart index a475a3ad..8f1929cf 100644 --- a/lib/services/concession_service.dart +++ b/lib/services/concession_service.dart @@ -74,6 +74,32 @@ class ConcessionService { } } + Future getConcessionRequest() async { + try { + var value = await concessionRequestCollection.doc(user!.uid).get(); + print('concession requests are being fetched '); + print(value.data()); + if (value.exists) { + print("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); + print("if"); + var detailsMap = value.data() as Map; + ConcessionRequestModel concessionRequestData = + ConcessionRequestModel.fromJson(detailsMap); + + return concessionRequestData; + } else { + + // Document does not exist + return null; + } + } catch (error) { + + // Handle any errors that might occur during the Firestore operation + print("Error fetching concession request: $error"); + return null; + } + } + Future uploadPhoto(File file, String docName) async { // idCard // prevpass