import 'package:doctor_app_flutter/models/patient/patient_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../providers/patients_provider.dart';

class PatientsListScreen extends StatefulWidget {
  @override
  _PatientsListScreenState createState() => _PatientsListScreenState();
}

class _PatientsListScreenState extends State<PatientsListScreen> {
  var _isInit = true;
  var _isLoading = true;
  var _hasError;
  @override
  void didChangeDependencies() {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatientModel patient = routeArgs['patientSearchForm'];
    print(patient.TokenID+"EEEEEE");
    String patientType = routeArgs['selectedType'];
    print(patientType);
    if (_isInit) {
      PatientsProvider patientsProv = Provider.of<PatientsProvider>(context);
      patientsProv.getPatientList(patient, patientType).then((res) {
        // print('MessageStatus${res['MessageStatus']}');
        print('List_MyInPatient${(res['List_MyInPatient'][0])}');
        setState(() {
          _isLoading = false;
        _hasError = res['ErrorEndUserMessage'];

        });
        print(res);
      }).catchError((error) {
        print(error);
      });
    }
    _isInit = false;
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PatientsListScreen'),
      ),
      body: _isLoading
          ? Center(
              child: CircularProgressIndicator(),
            )
          : Container(
              child: _hasError != null
                  ? Center(
                      child: Text(
                        _hasError,
                        style: TextStyle(color: Theme.of(context).errorColor),
                      ),
                    )
                  : Text('EEEEEEEEEEEEEE'),
            ),
    );
  }
}
/*
{ProjectID: 15, ClinicID: null, DoctorID: 4709, PatientID: 1288076, DoctorName: SHAZIA MAQSOOD, DoctorNameN: null, FirstName: LAMA, MiddleName: ABDULLAH, LastName: AL-SALOOM, FirstNameN: null, MiddleNameN: null, LastNameN: null, Gender: 2, DateofBirth: /Date(522363600000+0300)/, NationalityID: null, MobileNumber: 0543133371, EmailAddress: Lala_as@hotmail.com, PatientIdentificationNo: 1040451369, PatientType: 1, AdmissionNo: 2020008493, AdmissionDate: /Date(1587589200000+0300)/, RoomID: 119, BedID: 119, NursingStationID: null, Description: null, ClinicDescription: OB-GYNE, ClinicDescriptionN: null, NationalityName: Saudi, NationalityNameN: null, Age: 34 Yr, GenderDescription: Female, NursingStationName: Post Natal Ward – A2}
*/