Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

railway provider for concessionrequests made and some stuff #155

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions lib/new_ui/screens/railway_screen/railway_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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!)
: '';
Expand Down Expand Up @@ -475,7 +478,7 @@ class _RailwayConcessionScreenState
SizedBox(
height: 15,
),
if (lastPassIssued != null)
if (1==1)
Container(
width: size.width * 0.8,
child: Column(
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -123,6 +124,7 @@ class AuthProvider extends StateNotifier<bool> {
.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();
Expand Down
1 change: 1 addition & 0 deletions lib/provider/concession_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ class ConcessionProvider extends StateNotifier<bool> {
// debugPrint("concession: ${concessionDetailsData?.firstName}");
_ref.read(concessionDetailsProvider.notifier).state = concessionDetailsData;
}

}
42 changes: 42 additions & 0 deletions lib/provider/concession_request_provider.dart
Original file line number Diff line number Diff line change
@@ -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<ConcessionRequestModel?>((ref) {
return null;
});


final concessionRequestProvider = StateNotifierProvider<ConcessionRequestProvider, bool>((ref) {
return ConcessionRequestProvider(
concessionService: ref.watch(concessionServiceProvider), ref: ref);
});



class ConcessionRequestProvider extends StateNotifier<bool> {
final ConcessionService _concessionService;
final Ref _ref;

ConcessionRequestProvider({required ConcessionService concessionService, required Ref ref})
: _concessionService = concessionService,
_ref = ref,
super(false);

Future<void> 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
}
}
}
26 changes: 26 additions & 0 deletions lib/services/concession_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ class ConcessionService {
}
}

Future<ConcessionRequestModel?> 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<String, dynamic>;
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<String> uploadPhoto(File file, String docName) async {
// idCard
// prevpass
Expand Down
Loading