From 5d846d77eb5ce2e003b886e5e7959eb9ae55ce22 Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 16 Nov 2023 12:10:23 +0530 Subject: [PATCH] pull to refresh for get dynamic code --- lib/Reports/add_reports.dart | 172 ++++++++---- lib/Reports/all_records_tab.dart | 3 +- lib/common/dashboard.dart | 36 ++- lib/common/settings.dart | 86 +++++- lib/models/dynamic_code_model.dart | 18 ++ lib/models/get_connected_doctors_model.dart | 30 +++ lib/my_connections/add-doctor.dart | 161 +++++++++++ lib/my_connections/all_connections.dart | 270 ++++++++++++++++++- lib/my_connections/dynamic_code_doctor.dart | 281 ++++++++++++++++++++ pubspec.lock | 21 ++ pubspec.yaml | 4 + 11 files changed, 1023 insertions(+), 59 deletions(-) create mode 100644 lib/models/dynamic_code_model.dart create mode 100644 lib/models/get_connected_doctors_model.dart create mode 100644 lib/my_connections/add-doctor.dart create mode 100644 lib/my_connections/dynamic_code_doctor.dart diff --git a/lib/Reports/add_reports.dart b/lib/Reports/add_reports.dart index 29c585e..c01ac85 100644 --- a/lib/Reports/add_reports.dart +++ b/lib/Reports/add_reports.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:healthcare_user/common/settings.dart'; import 'package:healthcare_user/common/zoom_image.dart'; +import 'package:healthcare_user/models/get_connected_doctors_model.dart'; import 'package:intl/intl.dart'; import 'package:image_picker/image_picker.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; @@ -42,7 +43,35 @@ class _AddReportsState extends State { Map reports={}; Map prescriptions={}; String? prescriptionFor; + String? problemCategory; String? gender; + var doctorNameVariable; + + List connectedDoctorsListOriginal = []; + + Future getAllConnectedDoctors() async { + try { + var response = await AppSettings.getAllConnectedDoctors(); + + setState(() { + connectedDoctorsListOriginal = ((jsonDecode(response)) as List) + .map((dynamic model) { + return GetConnectedDoctorsModel.fromJson(model); + }).toList(); + //connectedDoctorsListOriginal=connectedDoctorsListOriginal.reversed.toList(); + //dateItemsVariable=connectedDoctorsListOriginal[0].doctor_name; + }); + } catch (e) { + AppSettings.longFailedToast('There is an issue please wait some time'); + } + } + + @override + void initState() { + getAllConnectedDoctors(); + super.initState(); + } + Future pickImageFromGallery() async { imageFileList = []; @@ -120,39 +149,6 @@ class _AddReportsState extends State { } } - /*Future pickImageFromGalleryForUpdate() async { - imageFileList = []; - final List? selectedImages = await imagePicker.pickMultiImage(); - AppSettings.preLoaderDialog(context); - if (selectedImages!.isNotEmpty) { - imageFileList.addAll(selectedImages); - } - - var res = await AppSettings.updateFindingsGallery(imageFileList,widget.recordId); - print(jsonDecode(res)); - Navigator.of(context, rootNavigator: true).pop(); - setState(() { - widget.imageDetails = jsonDecode(res)['findings']; - }); - } - - Future takeImageFromCameraForUpdate() async { - try { - final image = await _picker.pickImage(source: ImageSource.camera); - if (image == null) return; - final imageTemp = File(image.path); - AppSettings.preLoaderDialog(context); - var res = await AppSettings.updateFindingsCamera(image,widget.recordId); - print(jsonDecode(res)); - Navigator.of(context, rootNavigator: true).pop(); - setState(() { - widget.imageDetails = jsonDecode(res)['findings']; - }); - } on PlatformException catch (e) { - print('Failed to pick image: $e'); - } - }*/ - Future takeImageFromCameraForReports() async { try { final image = await _picker.pickImage(source: ImageSource.camera); @@ -227,8 +223,6 @@ class _AddReportsState extends State { }); } - - Future takeImageFromCameraForPrescriptions() async { try { final image = await _picker.pickImage(source: ImageSource.camera); @@ -348,7 +342,7 @@ class _AddReportsState extends State { return WillPopScope( onWillPop: () async => onWillPop(), child: Scaffold( - appBar: AppSettings.appBar('Reports'), + appBar: AppSettings.appBar('Add Record'), body: SingleChildScrollView( child: Container( child: Padding( @@ -356,7 +350,57 @@ class _AddReportsState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( + Container(child: DropdownButtonFormField( + // Initial Value + value: doctorNameVariable, + isExpanded: true, + decoration: const InputDecoration( + prefixIcon: Icon( + Icons.person, + color: greyColor, + ), + border: OutlineInputBorder( + borderSide: BorderSide(color: primaryColor)), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(color: primaryColor), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide(color: primaryColor), + ), + labelText: 'Select Doctor', + labelStyle: TextStyle( + color: greyColor, //<-- SEE HERE + ), + ), + + hint: Text('Please Select Doctor'), + // Down Arrow Icon + //icon: const Icon(Icons.keyboard_arrow_down), + + // Array list of items + items: connectedDoctorsListOriginal.map((items) { + return DropdownMenuItem( + value: items, + child: Text( + items.doctor_name, + style: TextStyle( + fontSize: 16, + ), + textAlign: TextAlign.center, + )); + }).toList(), + // After selecting the desired option,it will + // change button value to selected value + onChanged: ( newValue) { + setState(() { + doctorNameVariable = newValue; + }); + }, + ),), + SizedBox( + height: MediaQuery.of(context).size.height * .02, + ), + /* Container( child: TextFormField( cursorColor: greyColor, controller: doctorNameController, @@ -379,7 +423,7 @@ class _AddReportsState extends State { ), SizedBox( height: MediaQuery.of(context).size.height * .02, - ), + ),*/ Container( child: TextFormField( cursorColor: greyColor, @@ -436,6 +480,41 @@ class _AddReportsState extends State { }, ), ), + SizedBox( + height: MediaQuery.of(context).size.height * .02, + ), + Text('Select Problem Category',style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold,fontSize: 14),), + Row( + children: [ + Expanded( + child: RadioListTile( + title: Text("General"), + value: "general", + groupValue: problemCategory, + activeColor: primaryColor, + onChanged: (value) { + setState(() { + problemCategory = value.toString(); + }); + }, + ), + ), + Expanded( + child: RadioListTile( + title: Text("Confidential"), + value: "confidential", + groupValue: problemCategory, + activeColor: primaryColor, + onChanged: (value) { + setState(() { + problemCategory = value.toString(); + }); + }, + ), + ), + ], + ), + Text('Select Problem For',style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold,fontSize: 14),), Row( children: [ Expanded( @@ -466,6 +545,7 @@ class _AddReportsState extends State { ), ], ), + Visibility( visible: prescriptionFor.toString().toLowerCase() == 'others', @@ -1107,10 +1187,9 @@ class _AddReportsState extends State { onPrimary: Colors.black, // foreground ), onPressed: () async { - if (doctorNameController.text != '' && - problemController.text != '' && + if (problemController.text != '' && dateInput.text != '' && - prescriptionFor != '') { + prescriptionFor != ''&&problemCategory!='') { String _name = ''; String _age = ''; String? _gender = ''; @@ -1139,16 +1218,15 @@ class _AddReportsState extends State { var payload = new Map(); payload["problem"] = problemController.text.toString(); - payload["doctorName"] = - doctorNameController.text.toString(); - payload["hospitalName"] = - hospitalNameController.text.toString(); + payload["doctorName"] = doctorNameVariable.doctor_name.toString(); + payload["hospitalName"] = doctorNameVariable.hospital_name.toString(); + payload["doctorId"] = doctorNameVariable.doctor_id.toString(); payload["date"] = dateInput.text.toString(); payload["findings_date"] = ''; payload["reports_date"] = ''; payload["prescription_date"] = ''; - payload["patientType"] = - prescriptionFor.toString(); + payload["patientType"] = prescriptionFor.toString(); + payload["problemCategory"] = problemCategory.toString(); payload["others"] = { "name": _name, "age": int.parse(_age), diff --git a/lib/Reports/all_records_tab.dart b/lib/Reports/all_records_tab.dart index be36764..9a1979b 100644 --- a/lib/Reports/all_records_tab.dart +++ b/lib/Reports/all_records_tab.dart @@ -159,8 +159,7 @@ class _AllReportsTabState extends State return Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ - Expanded( - child: GridView.builder( + Expanded(child: GridView.builder( itemCount: widget.recordDetails.findingsImages.length, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, diff --git a/lib/common/dashboard.dart b/lib/common/dashboard.dart index d84d1ae..4b6975f 100644 --- a/lib/common/dashboard.dart +++ b/lib/common/dashboard.dart @@ -9,6 +9,7 @@ import 'package:healthcare_user/howareufeeling_today.dart'; import 'package:healthcare_user/invitations/invitations.dart'; import 'package:healthcare_user/medicines.dart'; import 'package:healthcare_user/my_connections/all_connections.dart'; +import 'package:healthcare_user/my_connections/dynamic_code_doctor.dart'; import 'package:healthcare_user/my_health.dart'; import 'package:healthcare_user/my_medicine_timings.dart'; import 'package:healthcare_user/prescriptions/prescriptions.dart'; @@ -641,8 +642,6 @@ class _DashboardState extends State { ), Container( - /*height:MediaQuery.of(context).size.height * 2.500, - width: MediaQuery.of(context).size.height * .05,*/ child: AppSettings.qrCode==''?TextButton( child: Text( 'GetQR', @@ -660,13 +659,11 @@ class _DashboardState extends State { var valueResponse = jsonDecode(value); String dataUri = jsonDecode(value)['qrCodeData']; -// Split the data URI at the comma to extract the Base64 part List parts = dataUri.split(","); String? base64String = parts.length == 2 ? parts[1] : null; if (base64String != null) { - // Now, you have the Base64-encoded image data in the 'base64String' variable - // You can use this 'base64String' in your Flutter code as needed + print(base64String); AppSettings.qrCode=base64String; } else { @@ -978,6 +975,35 @@ class _DashboardState extends State { Divider( color: Colors.grey, ), + ListTile( + title: Row( + children: [ + Image( + image: const AssetImage('images/updatemylocation.png'), + height: 25, + width: 25, + fit: BoxFit.fill), + const SizedBox( + width: 10, + ), + const SizedBox( + width: 10, + ), + Text('Dynamic Code', + style: drawerListItemsTextStyle()), + ], + ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const DynamicCode()), + ); + }, + ), + Divider( + color: Colors.grey, + ), ListTile( title: Row( children: [ diff --git a/lib/common/settings.dart b/lib/common/settings.dart index 46733c8..17fa76d 100644 --- a/lib/common/settings.dart +++ b/lib/common/settings.dart @@ -311,6 +311,10 @@ class AppSettings { static String addReportMySelfProblemUrl = host + 'insertReport'; static String getAllReportProblemDetalisUrl = host + 'userreport'; static String deleteReportMySelfProblemUrl = host + 'deleteReportProblem'; + static String getAllConnectedDoctorsDataUrl = host + 'connected-doctors'; + static String addDoctorUrl = host + 'user/connect-doctors'; + static String getDynamicCodeDataUrl = host + 'getDoctorInfo'; + @@ -1103,8 +1107,6 @@ class AppSettings { } - - static Future uploadVideoInReportMySelf(file) async { var request = http.MultipartRequest( 'POST', Uri.parse(reportMySelfVideoUploadUrl + '/' + customerId)); @@ -1801,6 +1803,86 @@ class AppSettings { } } + static Future getAllConnectedDoctors() async { + var uri = Uri.parse(getAllConnectedDoctorsDataUrl + '/' + customerId); + //uri = uri.replace(query: 'customerId=$customerId'); + + var response = await http.get(uri, headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return response.body; + } else if (response.statusCode == 401) { + bool status = await AppSettings.resetToken(); + if (status) { + response = await http.get(uri, headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return response.body; + } else { + return ''; + } + } else { + return ''; + } + } else { + return ''; + } + } + + static Future addDoctor(payload) async { + var uri = Uri.parse(addDoctorUrl + '/' + customerId); + var response = await http.post(uri, + body: json.encode(payload), headers: await buildRequestHeaders()); + + if (response.statusCode == 200) { + try { + var _response = json.decode(response.body); + print(_response); + return true; + } catch (e) { + // display error toast + return false; + } + } else if (response.statusCode == 401) { + bool status = await AppSettings.resetToken(); + if (status) { + response = await http.post(uri, + body: json.encode(payload), headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return true; + } else { + return false; + } + } else { + return false; + } + } else { + return false; + } + } + + static Future getDynamicCode() async { + var uri = Uri.parse(getDynamicCodeDataUrl + '/' + customerId); + //uri = uri.replace(query: 'customerId=$customerId'); + + var response = await http.get(uri, headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return response.body; + } else if (response.statusCode == 401) { + bool status = await AppSettings.resetToken(); + if (status) { + response = await http.get(uri, headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return response.body; + } else { + return ''; + } + } else { + return ''; + } + } else { + return ''; + } + } + /*Apis ends here*/ diff --git a/lib/models/dynamic_code_model.dart b/lib/models/dynamic_code_model.dart new file mode 100644 index 0000000..a60f6ac --- /dev/null +++ b/lib/models/dynamic_code_model.dart @@ -0,0 +1,18 @@ +class DynamicCodeModel { + String doctorId = ''; + String dynamicCode = ''; + String recordId = ''; + + DynamicCodeModel(); + + factory DynamicCodeModel.fromJson(Map json){ + DynamicCodeModel rtvm = new DynamicCodeModel(); + + rtvm.doctorId = json['doctorId'] ?? ''; + rtvm.dynamicCode= json['dynamicCode']??''; + rtvm.recordId= json['recordId']??''; + + return rtvm; + } + +} \ No newline at end of file diff --git a/lib/models/get_connected_doctors_model.dart b/lib/models/get_connected_doctors_model.dart new file mode 100644 index 0000000..53d6ea1 --- /dev/null +++ b/lib/models/get_connected_doctors_model.dart @@ -0,0 +1,30 @@ + + +class GetConnectedDoctorsModel { + String doctor_name=''; + String doctor_id=''; + String specialization=''; + String qualification=''; + String practiceplace1=''; + String practiceplace2=''; + String practiceplace3=''; + String hospital_name=''; + + + + + + GetConnectedDoctorsModel(); + + factory GetConnectedDoctorsModel.fromJson(Map json){ + GetConnectedDoctorsModel rtvm = new GetConnectedDoctorsModel(); + rtvm.doctor_name = json['doctorName'] ?? ''; + rtvm.specialization = json['specialization'] ?? ''; + rtvm.qualification = json['qualification'] ?? ''; + rtvm.doctor_id = json['doctorId'] ?? ''; + rtvm.hospital_name = json['placeOfPractice'][0]['hospitalName'] ?? ''; + + return rtvm; + } + +} \ No newline at end of file diff --git a/lib/my_connections/add-doctor.dart b/lib/my_connections/add-doctor.dart new file mode 100644 index 0000000..595e2a7 --- /dev/null +++ b/lib/my_connections/add-doctor.dart @@ -0,0 +1,161 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:healthcare_user/common/settings.dart'; +import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; + +class AddDoctor extends StatefulWidget { + const AddDoctor({Key? key}) : super(key: key); + + @override + State createState() => _AddDoctorState(); +} + +class _AddDoctorState extends State { + bool isPwdObscureText=true; + bool isFirstAddButtonShow=false; + bool isSecondAddButtonShow=false; + bool is2ndPlaceOfPracticeControllerVisible=false; + bool is3rdPlaceOfPracticeControllerVisible=false; + bool isConfirmPwdObscureText=true; + TextEditingController doctorIdController = TextEditingController(); + String? gender; + List placeOfPractices=[]; + final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); + bool isQrScannerVisible=false; + String doctorId=''; + + + @override + void initState() { + + super.initState(); + } + + + + Future scanQR() async { + String barcodeScanRes; + // Platform messages may fail, so we use a try/catch PlatformException. + try { + barcodeScanRes = await FlutterBarcodeScanner.scanBarcode( + '#ff6666', 'Cancel', true, ScanMode.QR); + print(barcodeScanRes); + setState(() { + doctorId=jsonDecode(barcodeScanRes)['doctorId']; + doctorIdController.text=doctorId; + }); + } on PlatformException { + barcodeScanRes = 'Failed to get platform version.'; + }} + + + + @override + Widget build(BuildContext context) { + + return Scaffold( + appBar:AppSettings.appBar('Add Doctor'), + body: Stack(children: [ + + GestureDetector( + onTap: () { + FocusScope.of(context).requestFocus(new FocusNode()); + }, + child: SafeArea( + child: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.all(10), + child: Column( + children: [ + SizedBox( + height:MediaQuery.of(context).size.height * .02, + ), + Container( + + child: Column( + children: [ + IconButton( + onPressed: (){ + scanQR(); + }, + icon: Icon( + Icons.qr_code_scanner, + color: primaryColor, + ), + ), + Text('Scan Qr Code',style: TextStyle(fontSize: 12,color: secondaryColor),) + ], + ) + ), + + SizedBox(height:MediaQuery.of(context).size.height * .02,), + Container( + child: TextFormField( + cursorColor: greyColor, + controller: doctorIdController, + decoration: const InputDecoration( + prefixIcon: Icon( + Icons.person, + color: greyColor, + ), + border: OutlineInputBorder( + borderSide: BorderSide(color: greyColor)), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(color: greyColor), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide(color: greyColor), + ), + labelText: 'Doctor Id', + labelStyle: TextStyle( + color: greyColor, //<-- SEE HERE + ), + ), + ), + ),//name + SizedBox(height:MediaQuery.of(context).size.height * .02,), + Container( + width:double.infinity, + height: MediaQuery.of(context).size.height * .06, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: primaryColor, // background + onPrimary: Colors.white, // foreground + ), + onPressed: () async{ + if(doctorIdController.text!=''){ + AppSettings.preLoaderDialog(context); + var payload = new Map(); + + payload["doctorId"] =doctorIdController.text.toString(); + + bool status = await AppSettings.addDoctor(payload); + if(status){ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longSuccessToast('Doctor added successfully'); + Navigator.pop(context); + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast('There is a problem for adding doctor'); + } + } + else{ + AppSettings.longFailedToast('Please enter valid details'); + } + + }, + child: Text('Add Doctor'), + ) + ), + + + ], + ), + ) + )), + ), + ])); + } +} diff --git a/lib/my_connections/all_connections.dart b/lib/my_connections/all_connections.dart index 79767e2..6a17531 100644 --- a/lib/my_connections/all_connections.dart +++ b/lib/my_connections/all_connections.dart @@ -1,5 +1,8 @@ +import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:healthcare_user/common/settings.dart'; +import 'package:healthcare_user/models/get_connected_doctors_model.dart'; +import 'package:healthcare_user/my_connections/add-doctor.dart'; class AllConnections extends StatefulWidget { const AllConnections({Key? key}) : super(key: key); @@ -8,12 +11,273 @@ class AllConnections extends StatefulWidget { State createState() => _AllConnectionsState(); } -class _AllConnectionsState extends State { +class _AllConnectionsState extends State + with TickerProviderStateMixin { + late TabController _controller; + bool isConnectedDoctorsDataLoading=false; + bool isSereverIssue=false; + + final List topTabs = [ + Tab( + child: Text( + 'Doctors', + style: TextStyle(fontSize: 14), + )), + Tab( + child: Text( + 'Pharmacies', + style: TextStyle(fontSize: 14), + )), + ]; + List connectedDoctorsListOriginal = []; + + @override + void initState() { + _controller = TabController(vsync: this, length: topTabs.length); + getAllConnectedDoctors(); + super.initState(); + } + + Future getAllConnectedDoctors() async { + isConnectedDoctorsDataLoading=true; + try { + var response = await AppSettings.getAllConnectedDoctors(); + + setState(() { + connectedDoctorsListOriginal = ((jsonDecode(response)) as List) + .map((dynamic model) { + return GetConnectedDoctorsModel.fromJson(model); + }).toList(); + connectedDoctorsListOriginal=connectedDoctorsListOriginal.reversed.toList(); + isConnectedDoctorsDataLoading = false; + }); + } catch (e) { + setState(() { + isConnectedDoctorsDataLoading = false; + isSereverIssue = true; + }); + } + } + + + Widget _doctors(){ + if(connectedDoctorsListOriginal.length!=0){ + return ListView.builder( + padding: EdgeInsets.all(0), + itemCount: connectedDoctorsListOriginal.length, + itemBuilder: (BuildContext context, int index) { + return GestureDetector( + onTap: (){ + + }, + child: Card( + + //color: prescriptionsList[index].cardColor, + child: Padding( + padding:EdgeInsets.all(8) , + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + + Container( + + + child: Row( + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Doctor Name', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + 'Hospital', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + 'Specialization', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + 'Qualification', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + + ], + ), + SizedBox(width:MediaQuery.of(context).size.width * .01,), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + ':', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + ':', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + ':', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + ':', + style: labelTextStyle(), + ), + + ], + ), + SizedBox(width:MediaQuery.of(context).size.width * .01,), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(connectedDoctorsListOriginal[index].doctor_name.toString().toUpperCase(),style: valuesTextStyle()), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + connectedDoctorsListOriginal[index].hospital_name, + style: valuesTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + connectedDoctorsListOriginal[index].specialization, + style: valuesTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + connectedDoctorsListOriginal[index].qualification, + style: valuesTextStyle(), + ), + ], + ), + ], + ), + + + + + ), + + ], + + ), + ], + ), + ), + ), + ); + }); + } + else{ + return Center( + child: Padding( + padding: EdgeInsets.fromLTRB(0, 40, 0, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(height: MediaQuery.of(context).size.height * .25,), + Text('Click below icon to add new doctor'), + SizedBox( + height: 20, + ), + CircleAvatar( + backgroundColor: primaryColor, + radius: 40, + child: IconButton( + iconSize: 40, + icon: const Icon( + Icons.add, + color: Colors.white, + ), + onPressed: () async { + Navigator.push(context, MaterialPageRoute(builder: (context) => AddDoctor())).then((value) { + getAllConnectedDoctors(); + }); + }, + ), + ) + ], + ), + ) + ); + } + + } + + Widget _pharmacies(){ + return Container(); + } + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppSettings.appBar('My Connections'), - body: Container(), + appBar: AppBar( + title: Text('My Connections'), + backgroundColor: primaryColor, + bottom: TabBar( + controller: _controller, + tabs: topTabs, + indicatorColor: buttonColors, + unselectedLabelColor: Colors.white60, + indicatorWeight: 2, + ), + ), + body: Container( + child: TabBarView(controller: _controller, children: [ + Padding(padding: EdgeInsets.all(10), + child:isConnectedDoctorsDataLoading?Center( + child: CircularProgressIndicator( + color: primaryColor, + strokeWidth: 5.0, + ), + ): _doctors(), + ), + Padding( + padding: EdgeInsets.all(10), + ) + ]), + ), + floatingActionButton: Visibility( + visible:connectedDoctorsListOriginal.length!=0, + child: CircleAvatar( + backgroundColor: buttonColors, + radius: 40, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + iconSize: 40, + icon: const Icon( + Icons.add, + color: Colors.black, + ), + onPressed: () async{ + + Navigator.push(context, MaterialPageRoute(builder: (context) => AddDoctor())).then((value) { + getAllConnectedDoctors(); + }); + }, + ), + + ], + ), + ), + ), ); } } diff --git a/lib/my_connections/dynamic_code_doctor.dart b/lib/my_connections/dynamic_code_doctor.dart new file mode 100644 index 0000000..5a7256d --- /dev/null +++ b/lib/my_connections/dynamic_code_doctor.dart @@ -0,0 +1,281 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:healthcare_user/common/settings.dart'; +import 'package:healthcare_user/models/dynamic_code_model.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; + +class DynamicCode extends StatefulWidget { + const DynamicCode({Key? key}) : super(key: key); + + @override + State createState() => _DynamicCodeState(); +} + +class _DynamicCodeState extends State { + + bool isDataLoading=false; + bool isSereverIssue = false; + List originalList = []; + List items = ["1", "2", "3", "4", "5", "6", "7", "8"]; + RefreshController _refreshController = + RefreshController(initialRefresh: true); + + @override + void initState() { + getAllDynamicCodes(); + super.initState(); + } + + Future getAllDynamicCodes() async { + isDataLoading=true; + try { + var response = await AppSettings.getDynamicCode(); + + setState(() { + originalList = ((jsonDecode(response)) as List) + .map((dynamic model) { + return DynamicCodeModel.fromJson(model); + }).toList(); + originalList=originalList.reversed.toList(); + isDataLoading = false; + }); + } catch (e) { + setState(() { + isDataLoading = false; + isSereverIssue = true; + }); + } + } + + void _onRefresh() async{ + // monitor network fetch + await Future.delayed(Duration(milliseconds: 1000)); + // if failed,use refreshFailed() + /*items.remove((items.length-1).toString()); + if(mounted) + setState(() { + + });*/ + await getAllDynamicCodes(); + _refreshController.refreshCompleted( + resetFooterState: true, + ); + } + + void _onLoading() async{ + // monitor network fetch + await Future.delayed(Duration(milliseconds: 1000)); + // if failed,use loadFailed(),if no data return,use LoadNodata() + items.add((items.length+1).toString()); + if(mounted) + setState(() { + + }); + _refreshController.loadComplete(); + } + + Widget _renderUi(){ + if(originalList.length!=0){ + return ListView.builder( + padding: EdgeInsets.all(0), + itemCount: originalList.length, + itemBuilder: (BuildContext context, int index) { + return GestureDetector( + onTap: (){ + + }, + child: Card( + + //color: prescriptionsList[index].cardColor, + child: Padding( + padding:EdgeInsets.all(8) , + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + + Container( + + + child: Row( + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Doctor Id', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + 'Dynamic code', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + 'Record Id', + style: labelTextStyle(), + ), + + ], + ), + SizedBox(width:MediaQuery.of(context).size.width * .01,), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + ':', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + ':', + style: labelTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + ':', + style: labelTextStyle(), + ), + + + ], + ), + SizedBox(width:MediaQuery.of(context).size.width * .01,), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(originalList[index].doctorId.toString().toUpperCase(),style: valuesTextStyle()), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + originalList[index].dynamicCode, + style: valuesTextStyle(), + ), + SizedBox(height:MediaQuery.of(context).size.height * .01,), + Text( + originalList[index].recordId, + style: valuesTextStyle(), + ), + ], + ), + ], + ), + + + + + ), + + ], + + ), + ], + ), + ), + ), + ); + }); + } + else{ + return Center( + child: Padding( + padding: EdgeInsets.fromLTRB(0, 40, 0, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(height: MediaQuery.of(context).size.height * .25,), + Text('No Dynamic Codes available'), + SizedBox( + height: 20, + ), + CircleAvatar( + backgroundColor: primaryColor, + radius: 40, + child: IconButton( + iconSize: 40, + icon: const Icon( + Icons.info, + color: Colors.white, + ), + onPressed: () async { + + }, + ), + ) + ], + ), + ) + ); + } + } + + + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppSettings.appBar('Dynamic Code'), + body: SmartRefresher( + enablePullDown: true, + enablePullUp: false, + /* header: WaterDropHeader( + waterDropColor: primaryColor, + ),*/ + header: CustomHeader( + builder: (BuildContext context, RefreshStatus? mode) { + return Container( + child: Center( + child: CircularProgressIndicator( + // Set the color of the circular progress indicator + valueColor: AlwaysStoppedAnimation(primaryColor), + ), + ), + ); + }, + ), + footer: CustomFooter( + builder: (BuildContext context,LoadStatus? mode){ + Widget body ; + if(mode==LoadStatus.idle){ + body = Text("pull up load"); + } + else if(mode==LoadStatus.loading){ + body = Container(); + } + else if(mode == LoadStatus.failed){ + body = Text("Load Failed!Click retry!"); + } + else if(mode == LoadStatus.canLoading){ + body = Text("release to load more"); + } + else{ + body = Text("No more Data"); + } + return Container( + height: 55.0, + child: Center(child:body), + ); + }, + ), + controller: _refreshController, + onRefresh: _onRefresh, + onLoading: _onLoading, + + child:_renderUi() + + /*ListView.builder( + itemBuilder: (c, i) => Card(child: Center(child: Text(items[i]))), + itemExtent: 100.0, + itemCount: items.length, + ),*/ + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 3a0be6f..2d2c55f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -370,6 +370,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_barcode_scanner: + dependency: "direct main" + description: + name: flutter_barcode_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" flutter_cupertino_datetime_picker: dependency: "direct main" description: @@ -1052,6 +1059,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.0.5" + pull_to_refresh: + dependency: "direct main" + description: + name: pull_to_refresh + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" qr: dependency: transitive description: @@ -1059,6 +1073,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + qr_code_scanner: + dependency: "direct main" + description: + name: qr_code_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" qr_flutter: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 3834fd9..53af8ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,6 +64,10 @@ dependencies: flutter_share: ^2.0.0 share: ^2.0.4 qr_flutter: ^4.0.0 + qr_code_scanner: ^1.0.1 + flutter_barcode_scanner: ^2.0.0 + pull_to_refresh: ^2.0.0 + dev_dependencies: flutter_test: