You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/lib/providers/doctor_reply_provider.dart

62 lines
2.0 KiB
Dart

import 'dart:convert';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/models/request_doctor_reply.dart';
import 'package:doctor_app_flutter/models/list_gt_my_pationents_question_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_client_with_interceptor.dart';
import '../interceptor/http_interceptor.dart';
class DoctorReplyProvider with ChangeNotifier {
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
List<ListGtMyPatientsQuestions> listDoctorWorkingHoursTable = [];
bool isLoading = true;
bool isError = false;
String error = '';
RequestDoctorReply _requestSchedule = RequestDoctorReply();
DoctorReplyProvider() {
getDoctorSchedule();
}
getDoctorSchedule() async {
const url = BASE_URL + 'DoctorApplication.svc/REST/GtMyPatientsQuestions';
try {
if (await Helpers.checkConnection()) {
final response = await client.post(url,
body: json.encode(_requestSchedule.toJson()));
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode >= 400 || json == null) {
isLoading = false;
isError = true;
error = 'Error While Fetching data';
} else {
var parsed = json.decode(response.body.toString());
if (parsed['MessageStatus'] == 1) {
parsed['List_GtMyPatientsQuestions'].forEach((v) {
listDoctorWorkingHoursTable.add( ListGtMyPatientsQuestions.fromJson(v));
});
isError = false;
isLoading = false;
} else {
isError = true;
error = parsed['ErrorMessage'] ?? parsed['ErrorEndUserMessage'];
}
}
} else {
isLoading = false;
isError = true;
error = 'Please Check The Internet Connection';
}
notifyListeners();
} catch (error) {
throw error;
}
}
}