diff --git a/lib/models/ScheduleRequest.dart b/lib/models/ScheduleRequest.dart new file mode 100644 index 00000000..7114948a --- /dev/null +++ b/lib/models/ScheduleRequest.dart @@ -0,0 +1,68 @@ +class ScheduleRequest { + int projectID; + int clinicID; + int doctorID; + int doctorWorkingHoursDays; + int languageID; + String stamp; + String iPAdress; + double versionID; + int channel; + String tokenID; + String sessionID; + bool isLoginForDoctorApp; + bool patientOutSA; + int patientTypeID; + + ScheduleRequest( + this.projectID, + this.clinicID, + this.doctorID, + this.doctorWorkingHoursDays, + this.languageID, + this.stamp, + this.iPAdress, + this.versionID, + this.channel, + this.tokenID, + this.sessionID, + this.isLoginForDoctorApp, + this.patientOutSA, + this.patientTypeID); + + ScheduleRequest.fromJson(Map json) { + projectID = json['ProjectID']; + clinicID = json['ClinicID']; + doctorID = json['DoctorID']; + doctorWorkingHoursDays = json['DoctorWorkingHoursDays']; + languageID = json['LanguageID']; + stamp = json['stamp']; + iPAdress = json['IPAdress']; + versionID = json['VersionID']; + channel = json['Channel']; + tokenID = json['TokenID']; + sessionID = json['SessionID']; + isLoginForDoctorApp = json['IsLoginForDoctorApp']; + patientOutSA = json['PatientOutSA']; + patientTypeID = json['PatientTypeID']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + data['ClinicID'] = this.clinicID; + data['DoctorID'] = this.doctorID; + data['DoctorWorkingHoursDays'] = this.doctorWorkingHoursDays; + data['LanguageID'] = this.languageID; + data['stamp'] = this.stamp; + data['IPAdress'] = this.iPAdress; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['TokenID'] = this.tokenID; + data['SessionID'] = this.sessionID; + data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp; + data['PatientOutSA'] = this.patientOutSA; + data['PatientTypeID'] = this.patientTypeID; + return data; + } +} diff --git a/lib/models/list_doctor_working_hours_table_model.dart b/lib/models/list_doctor_working_hours_table_model.dart new file mode 100644 index 00000000..4a46e925 --- /dev/null +++ b/lib/models/list_doctor_working_hours_table_model.dart @@ -0,0 +1,21 @@ +class ListDoctorWorkingHoursTable { + String date; + String dayName; + String workingHours; + + ListDoctorWorkingHoursTable({this.date, this.dayName, this.workingHours}); + + ListDoctorWorkingHoursTable.fromJson(Map json) { + date = json['Date']; + dayName = json['DayName']; + workingHours = json['WorkingHours']; + } + + Map toJson() { + final Map data = new Map(); + data['Date'] = this.date; + data['DayName'] = this.dayName; + data['WorkingHours'] = this.workingHours; + return data; + } +} diff --git a/lib/providers/schedule_provider.dart b/lib/providers/schedule_provider.dart new file mode 100644 index 00000000..05056c3c --- /dev/null +++ b/lib/providers/schedule_provider.dart @@ -0,0 +1,70 @@ +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/ScheduleRequest.dart'; + +class ScheduleProvider with ChangeNotifier { + Client client = + HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); + + List listDoctorWorkingHoursTable = []; + bool isLoading = true; + bool isError = false; + String error = ''; + ScheduleRequest scheduleRequest = ScheduleRequest( + 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() { + geDoctorSchedule(); + } + + geDoctorSchedule() async { + const url = BASE_URL + 'Doctors.svc/REST/GetDoctorWorkingHoursTable'; + try { + if (await Helpers.checkConnection()) { + final response = await client.post(url, body: json.encode(scheduleRequest.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; + } + } +} diff --git a/lib/screens/my_schedule_screen.dart b/lib/screens/my_schedule_screen.dart index 0c4593ad..fd360775 100644 --- a/lib/screens/my_schedule_screen.dart +++ b/lib/screens/my_schedule_screen.dart @@ -1,41 +1,63 @@ +import 'package:doctor_app_flutter/providers/schedule_provider.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import '../config/size_config.dart'; import '../widgets/shared/app_scaffold_widget.dart'; import '../widgets/shared/card_with_bg_widget.dart'; class MyScheduleScreen extends StatelessWidget { - List litems = [ - "1", - "2", - ]; + ScheduleProvider scheduleProvider; @override Widget build(BuildContext context) { + scheduleProvider = Provider.of(context); return AppScaffold( - // pageOnly: false, - appBarTitle: 'My Schdule', - body: Container( - padding: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: ListView(children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 20, + // pageOnly: false, + appBarTitle: 'My Schdule', + body: scheduleProvider.isLoading + ? Center( + child: CircularProgressIndicator(), + ) + : scheduleProvider.isError + ? Center( + child: Text( + scheduleProvider.error, + style: TextStyle(color: Theme.of(context).errorColor), + ), + ) + : scheduleProvider.listDoctorWorkingHoursTable.length == 0 + ? Center( + child: Text( + 'You don\'t have any Schedule', + style: TextStyle(color: Theme.of(context).errorColor), + ), + ) + : Container( + padding: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + child: ListView( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 20, + ), + Text('My Schedule', + style: textStyle(2.5, FontWeight.w700)), + scheduleListByDate('Today, 7 April '), + // scheduleListByDate('Wednesday, 8 April '), + ], + ), + ], + ), + ], + ), ), - Text('My Schedule', style: textStyle(2.5, FontWeight.w700)), - scheduleListByDate('Today, 7 April '), - scheduleListByDate('Wednesday, 8 April '), - ], - ), - ], - ), - ]), - )); + ); } Column scheduleListByDate(date) { @@ -45,11 +67,16 @@ class MyScheduleScreen extends StatelessWidget { SizedBox( height: 10, ), - Text(date, style: textStyle(2.5)), + // Text(date, style: textStyle(2.5)), Container( child: Column( - children: litems.map((item) { - return CardWithBgWidget(line1Text: 'ER new development ideas meeting',line2Text:'09:00 AM - 10:50 AM',line3Text: 'Cloud Solution',icon: Icons.add_location, heightPercentage: 0.20, widthPercentage: 0.80,); + children: scheduleProvider.listDoctorWorkingHoursTable.map((item) { + return CardWithBgWidget( + line1Text: item.dayName, + line2Text:item.workingHours , + heightPercentage: 0.18, + widthPercentage: 0.80, + ); }).toList(), ), ), @@ -62,4 +89,3 @@ class MyScheduleScreen extends StatelessWidget { fontSize: size * SizeConfig.textMultiplier, fontWeight: weight); } } - diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index fb303a15..a1197e04 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -4,6 +4,9 @@ import 'package:flutter/material.dart'; import '../config/size_config.dart'; import '../util/dr_app_toast_msg.dart'; +import 'package:connectivity/connectivity.dart'; + + DrAppToastMsg toastMsg = DrAppToastMsg(); /* *@author: Elham Rababah @@ -69,4 +72,15 @@ class Helpers { toastMsg.showErrorToast(localMsg); } + + static Future checkConnection() async { + ConnectivityResult connectivityResult = + await (Connectivity().checkConnectivity()); + if ((connectivityResult == ConnectivityResult.mobile) || + (connectivityResult == ConnectivityResult.wifi)) { + return true; + } else { + return false; + } + } } diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index 4651684c..d831ab7b 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -1,6 +1,9 @@ +import 'package:doctor_app_flutter/providers/schedule_provider.dart'; import 'package:doctor_app_flutter/routes.dart'; +import 'package:doctor_app_flutter/screens/my_schedule_screen.dart'; import 'package:doctor_app_flutter/screens/profile_screen.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import '../../config/size_config.dart'; import '../../widgets/shared/drawer_item_widget.dart'; @@ -57,7 +60,9 @@ class _AppDrawerState extends State { InkWell( child: DrawerItem("My Schedule", Icons.table_chart), onTap: () { - Navigator.of(context).pushNamed(MY_SCHEDULE); + Navigator.push(context,MaterialPageRoute( + builder: (context) => ChangeNotifierProvider.value(value: ScheduleProvider(),child: MyScheduleScreen(),), + ),); }, ), InkWell(child: DrawerItem("Settings", Icons.settings), onTap: (){ diff --git a/lib/widgets/shared/card_with_bg_widget.dart b/lib/widgets/shared/card_with_bg_widget.dart index 1936b586..d9579ff9 100644 --- a/lib/widgets/shared/card_with_bg_widget.dart +++ b/lib/widgets/shared/card_with_bg_widget.dart @@ -6,15 +6,11 @@ import 'package:hexcolor/hexcolor.dart'; class CardWithBgWidget extends StatelessWidget { String line1Text; String line2Text; - String line3Text; - IconData icon; double heightPercentage; double widthPercentage; CardWithBgWidget( {this.line1Text = '', this.line2Text = '', - this.line3Text = '', - this.icon, this.heightPercentage, this.widthPercentage}); @@ -43,20 +39,20 @@ class CardWithBgWidget extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(line1Text, style: textStyle(2.5)), + Text(line1Text, style: textStyle(2.5)) , SizedBox( height: 8, ), - Text(line2Text, style: textStyle(2.5)), - SizedBox( - height: 8, - ), - Row( - children: [ - Icon(icon), - Text(line3Text, style: textStyle(2.5)) + !line2Text.contains('and')? + Text(line2Text, style: textStyle(2.5)) : + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(line2Text.substring(0,line2Text.indexOf('a')), style: textStyle(2.5)) , + Text(line2Text.substring(line2Text.indexOf('d')+2,), style: textStyle(2.5)) , ], - ) + ), + ], ), ), diff --git a/pubspec.lock b/pubspec.lock index e717a7f9..8cd1be91 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -35,7 +35,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.4.1" bazel_worker: dependency: transitive description: @@ -49,7 +49,7 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" build: dependency: transitive description: @@ -126,7 +126,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" checked_yaml: dependency: transitive description: @@ -134,6 +134,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" code_builder: dependency: transitive description: @@ -147,7 +154,28 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" + connectivity: + dependency: "direct main" + description: + name: connectivity + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.8+2" + connectivity_macos: + dependency: transitive + description: + name: connectivity_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0+2" + connectivity_platform_interface: + dependency: transitive + description: + name: connectivity_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" convert: dependency: transitive description: @@ -183,6 +211,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.4" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" fixnum: dependency: transitive description: @@ -289,13 +324,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.10" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" imei_plugin: dependency: "direct main" description: @@ -393,7 +421,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.7.0" pedantic: dependency: transitive description: @@ -408,20 +436,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1+1" - petitparser: + platform: dependency: transitive description: - name: petitparser + name: platform url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" - platform: + version: "2.2.1" + plugin_platform_interface: dependency: transitive description: - name: platform + name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "1.0.2" pool: dependency: transitive description: @@ -552,7 +580,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -594,7 +622,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.15" timing: dependency: transitive description: @@ -630,13 +658,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" yaml: dependency: transitive description: @@ -646,4 +667,4 @@ packages: version: "2.2.0" sdks: dart: ">=2.7.0 <3.0.0" - flutter: ">=1.12.13+hotfix.4 <2.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 996ef2fc..1f7041ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: local_auth: ^0.6.1+3 http_interceptor: ^0.2.0 progress_hud_v2: ^2.0.0 + connectivity: ^0.4.8+2 # The following adds the Cupertino Icons font to your application.