From 0799c749571364974c8cef057eae397ba42f9dd6 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 11 Mar 2020 18:27:39 +0200 Subject: [PATCH] fix the calling api --- lib/providers/patients_provider.dart | 3 ++- .../patients/patients_list_screen.dart | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 1d5c3d29..1e747906 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -6,7 +6,7 @@ import 'package:http/http.dart' as http; import 'dart:convert'; class PatientsProvider with ChangeNotifier { - Future getPatientList(PatientModel patient, patientType) async { + Future getPatientList(PatientModel patient, patientType) async { Map requestHeaders = { 'Content-type': 'application/json', 'Accept': 'application/json', @@ -41,6 +41,7 @@ class PatientsProvider with ChangeNotifier { // var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'}); print('Response status: ${response.statusCode}'); print('Response body: ${response.body}'); + return Future.value(json.decode(response.body)); notifyListeners(); } catch (error) { print(error.toString()); diff --git a/lib/screens/patients/patients_list_screen.dart b/lib/screens/patients/patients_list_screen.dart index 00fd4d7a..168f41bd 100644 --- a/lib/screens/patients/patients_list_screen.dart +++ b/lib/screens/patients/patients_list_screen.dart @@ -8,16 +8,31 @@ class PatientsList extends StatefulWidget { } class _PatientsListState extends State { - @override - Widget build(BuildContext context) { + var _isInit =true; + @override + void didChangeDependencies() { final routeArgs = ModalRoute.of(context).settings.arguments as Map; PatientModel patient = routeArgs['patientSearchForm']; String patientType = routeArgs['selectedType']; print(patientType); - var list ; - + if(_isInit) { + setState(() { + + }); PatientsProvider patientsProv = Provider.of(context); - patientsProv.getPatientList(patient, patientType); + patientsProv.getPatientList(patient, patientType).then((res){ + print('Response EEEEEEEE: ${res}'); + print(res['ServiceName']); + }); + } + _isInit = false; + super.didChangeDependencies(); + + } + @override + Widget build(BuildContext context) { + + return Scaffold( appBar: AppBar(title: Text('PatientsList'),), );