import 'dart:convert'; import 'package:doctor_app_flutter/config/config.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/RequestSchedule.dart'; class ScheduleProvider with ChangeNotifier { Client client = HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); List listDoctorWorkingHoursTable = []; bool isLoading = true; bool isError = false; String error = ''; RequestSchedule requestSchedule = RequestSchedule(15, 1, 70907, 7, 2, '2020-04-22T11:25:57.640Z', '11.11.11.11', 1.2, 9, '2lMDFT8U+Uy5jxRzCO8n2w==', 'vV6tg9yyVJ222', true, false, 1); ScheduleProvider() { getDoctorSchedule(); } getDoctorSchedule() async { const url = BASE_URL + 'Doctors.svc/REST/GetDoctorWorkingHoursTable'; 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; } } }