106 lines
3.1 KiB
Dart
106 lines
3.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:onufitness/constants/api_endpoints.dart';
|
|
import 'package:onufitness/services/api_services/base_api_services.dart';
|
|
import 'package:onufitness/utils/custom_sneakbar.dart';
|
|
|
|
class ProfessionalInfoController extends GetxController {
|
|
TextEditingController experienceTextController = TextEditingController();
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
onInitApiCall();
|
|
experienceTextController = TextEditingController();
|
|
}
|
|
|
|
onInitApiCall() async {
|
|
await getProfessionalInfoApiCall();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
experienceTextController.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
//..............................................................................................................
|
|
var specializations = <String>[].obs;
|
|
|
|
void addSpecialization(String specialization) {
|
|
if (specialization.isNotEmpty &&
|
|
!specializations.contains(specialization)) {
|
|
specializations.add(specialization);
|
|
}
|
|
}
|
|
|
|
void removeSpecialization(String specialization) {
|
|
specializations.remove(specialization);
|
|
}
|
|
|
|
//..............................................................................................................
|
|
RxBool isfetchProfInfoLoading = false.obs;
|
|
|
|
getProfessionalInfoApiCall() async {
|
|
isfetchProfInfoLoading(true);
|
|
try {
|
|
var response = await ApiBase.getRequest(
|
|
extendedURL: ApiUrl.getCoachProfessionalInfo,
|
|
sendHeaders: true,
|
|
);
|
|
log(response.statusCode.toString());
|
|
log(response.body.toString());
|
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
|
var body = jsonDecode(response.body);
|
|
if (body["data"]["yearOfExperience"] != null) {
|
|
experienceTextController.text =
|
|
body["data"]["yearOfExperience"].toString();
|
|
}
|
|
} else {
|
|
customSnackbar(
|
|
title: "Failed",
|
|
message: "Failed to fetch year of experience",
|
|
);
|
|
}
|
|
} catch (e) {
|
|
log("Error fetching professional info: ${e.toString()}");
|
|
}
|
|
isfetchProfInfoLoading(false);
|
|
}
|
|
|
|
RxBool isUpdateProfInfoLoading = false.obs;
|
|
|
|
updateProfessionalInfoApiCall() async {
|
|
isUpdateProfInfoLoading(true);
|
|
try {
|
|
var response = await ApiBase.patchRequest(
|
|
extendedURL: ApiUrl.updateCoachProfessionalInfo,
|
|
body: {"yearOfExperience": experienceTextController.text.trim()},
|
|
);
|
|
log(response.body.toString());
|
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
|
customSnackbar(
|
|
title: "Success",
|
|
message: "Experience Updated Successfully",
|
|
duration: 1,
|
|
);
|
|
} else {
|
|
customSnackbar(
|
|
title: "Failed",
|
|
message: "Failed to update experience",
|
|
duration: 1,
|
|
);
|
|
}
|
|
} catch (e) {
|
|
customSnackbar(
|
|
title: "Failed",
|
|
message: "Failed to update experience",
|
|
duration: 1,
|
|
);
|
|
}
|
|
isUpdateProfInfoLoading(false);
|
|
}
|
|
}
|