import 'dart:convert'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/models/doctor_profile_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'; import '../models/list_doctor_working_hours_table_model.dart'; import '../models/request_schedule.dart'; class ScheduleProvider with ChangeNotifier { Client client = HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); List listDoctorWorkingHoursTable = []; bool isLoading = true; bool isError = false; String error = ''; RequestSchedule requestSchedule = RequestSchedule(); ScheduleProvider() { getDoctorSchedule(); } getDoctorSchedule() async { const url = BASE_URL + 'Doctors.svc/REST/GetDoctorWorkingHoursTable'; Map profile = await sharedPref.getObj(DOCTOR_PROFILE); String token = await sharedPref.getString(TOKEN); DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); requestSchedule.doctorID = doctorProfile.doctorID; requestSchedule.projectID = doctorProfile.projectID; requestSchedule.clinicID = doctorProfile.clinicID; requestSchedule.tokenID = token; 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()); parsed['List_DoctorWorkingHoursTable'].forEach((v) { listDoctorWorkingHoursTable .add(new ListDoctorWorkingHoursTable.fromJson(v)); }); isError = false; isLoading = false; } } else { isLoading = false; isError = true; error = 'Please Check The Internet Connection'; } notifyListeners(); } catch (error) { throw error; } } }