You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			462 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			462 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			Dart
		
	
import 'package:doctor_app_flutter/config/config.dart';
 | 
						|
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
 | 
						|
import 'package:doctor_app_flutter/core/model/patient_muse/PatientSearchRequestModel.dart';
 | 
						|
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
 | 
						|
import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart';
 | 
						|
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
 | 
						|
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
 | 
						|
import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart';
 | 
						|
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
 | 
						|
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
 | 
						|
import 'package:doctor_app_flutter/models/patient/patient_model.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/base/base_view.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/home/dashboard_slider-item-widget.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/home/dashboard_swipe_widget.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/home/home_patient_card.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/live_care/live_care_patient_screen.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/patients/PatientsInPatientScreen.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/patients/out_patient/out_patient_screen.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_screen.dart';
 | 
						|
import 'package:doctor_app_flutter/screens/patients/profile/referral/patient_referral_screen.dart';
 | 
						|
import 'package:doctor_app_flutter/util/date-utils.dart';
 | 
						|
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
 | 
						|
import 'package:doctor_app_flutter/util/helpers.dart';
 | 
						|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
 | 
						|
import 'package:doctor_app_flutter/widgets/patients/profile/profile-welcome-widget.dart';
 | 
						|
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
 | 
						|
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
 | 
						|
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
 | 
						|
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
 | 
						|
import 'package:flutter/cupertino.dart';
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
import 'package:provider/provider.dart';
 | 
						|
import 'package:sticky_headers/sticky_headers/widget.dart';
 | 
						|
 | 
						|
import '../../widgets/shared/app_texts_widget.dart';
 | 
						|
 | 
						|
class HomeScreen extends StatefulWidget {
 | 
						|
  HomeScreen({Key key, this.title}) : super(key: key);
 | 
						|
 | 
						|
  final String title;
 | 
						|
  final String iconURL = 'assets/images/dashboard_icon/';
 | 
						|
 | 
						|
  @override
 | 
						|
  _HomeScreenState createState() => _HomeScreenState();
 | 
						|
}
 | 
						|
 | 
						|
class _HomeScreenState extends State<HomeScreen> {
 | 
						|
  bool isLoading = false;
 | 
						|
  ProjectViewModel projectsProvider;
 | 
						|
  var _isInit = true;
 | 
						|
  DoctorProfileModel profile;
 | 
						|
  bool isExpanded = false;
 | 
						|
  bool isInpatient = false;
 | 
						|
  int sliderActiveIndex = 0;
 | 
						|
  var clinicId;
 | 
						|
  AuthenticationViewModel authenticationViewModel;
 | 
						|
  int colorIndex = 0;
 | 
						|
 | 
						|
  @override
 | 
						|
  Widget build(BuildContext context) {
 | 
						|
    ProjectViewModel projectsProvider = Provider.of<ProjectViewModel>(context);
 | 
						|
    authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
 | 
						|
 | 
						|
    FocusScopeNode currentFocus = FocusScope.of(context);
 | 
						|
    if (!currentFocus.hasPrimaryFocus) {
 | 
						|
      currentFocus.unfocus();
 | 
						|
    }
 | 
						|
 | 
						|
    return BaseView<DashboardViewModel>(
 | 
						|
      onModelReady: (model) async {
 | 
						|
        await model.setFirebaseNotification(
 | 
						|
            projectsProvider, authenticationViewModel);
 | 
						|
        await model.getDashboard();
 | 
						|
        await model.getDoctorProfile(isGetProfile: true);
 | 
						|
        await model.checkDoctorHasLiveCare();
 | 
						|
      },
 | 
						|
      builder: (_, model, w) => AppScaffold(
 | 
						|
        baseViewModel: model,
 | 
						|
        isShowAppBar: false,
 | 
						|
        body: ListView(children: [
 | 
						|
          Column(children: <Widget>[
 | 
						|
            StickyHeader(
 | 
						|
              header: Container(
 | 
						|
                  color: Colors.grey[100],
 | 
						|
                  padding: EdgeInsets.only(top: 10),
 | 
						|
                  child: Stack(children: [
 | 
						|
                    IconButton(
 | 
						|
                      icon: Image.asset('assets/images/menu.png',
 | 
						|
                          height: 50, width: 50),
 | 
						|
                      iconSize: 18,
 | 
						|
                      color: Colors.black,
 | 
						|
                      onPressed: () => Scaffold.of(context).openDrawer(),
 | 
						|
                    ),
 | 
						|
                    Column(children: <Widget>[
 | 
						|
                      ProfileWelcomeWidget(
 | 
						|
                        Row(
 | 
						|
                          mainAxisAlignment: MainAxisAlignment.start,
 | 
						|
                          children: [
 | 
						|
                            Container(
 | 
						|
                              width: MediaQuery.of(context).size.width * .6,
 | 
						|
                              child: projectsProvider.doctorClinicsList.length >
 | 
						|
                                      0
 | 
						|
                                  ? Stack(
 | 
						|
                                      children: [
 | 
						|
                                        DropdownButtonHideUnderline(
 | 
						|
                                            child: DropdownButton(
 | 
						|
                                          dropdownColor: Colors.white,
 | 
						|
                                          iconEnabledColor: Colors.black,
 | 
						|
                                          isExpanded: true,
 | 
						|
                                          value: clinicId == null
 | 
						|
                                              ? projectsProvider
 | 
						|
                                                  .doctorClinicsList[0].clinicID
 | 
						|
                                              : clinicId,
 | 
						|
                                          iconSize: 25,
 | 
						|
                                          elevation: 16,
 | 
						|
                                          selectedItemBuilder:
 | 
						|
                                              (BuildContext context) {
 | 
						|
                                            return projectsProvider
 | 
						|
                                                .doctorClinicsList
 | 
						|
                                                .map((item) {
 | 
						|
                                              return Row(
 | 
						|
                                                mainAxisSize: MainAxisSize.max,
 | 
						|
                                                mainAxisAlignment:
 | 
						|
                                                    MainAxisAlignment.end,
 | 
						|
                                                children: <Widget>[
 | 
						|
                                                  Column(
 | 
						|
                                                    mainAxisAlignment:
 | 
						|
                                                        MainAxisAlignment
 | 
						|
                                                            .center,
 | 
						|
                                                    children: [
 | 
						|
                                                      Container(
 | 
						|
                                                          padding:
 | 
						|
                                                              EdgeInsets.all(2),
 | 
						|
                                                          margin:
 | 
						|
                                                              EdgeInsets.all(2),
 | 
						|
                                                          decoration:
 | 
						|
                                                              new BoxDecoration(
 | 
						|
                                                            color:
 | 
						|
                                                                Colors.red[800],
 | 
						|
                                                            borderRadius:
 | 
						|
                                                                BorderRadius
 | 
						|
                                                                    .circular(
 | 
						|
                                                                        20),
 | 
						|
                                                          ),
 | 
						|
                                                          constraints:
 | 
						|
                                                              BoxConstraints(
 | 
						|
                                                            minWidth: 20,
 | 
						|
                                                            minHeight: 20,
 | 
						|
                                                          ),
 | 
						|
                                                          child: Center(
 | 
						|
                                                            child: AppText(
 | 
						|
                                                              projectsProvider
 | 
						|
                                                                  .doctorClinicsList
 | 
						|
                                                                  .length
 | 
						|
                                                                  .toString(),
 | 
						|
                                                              color:
 | 
						|
                                                                  Colors.white,
 | 
						|
                                                              fontSize:
 | 
						|
                                                                  projectsProvider
 | 
						|
                                                                          .isArabic
 | 
						|
                                                                      ? 10
 | 
						|
                                                                      : 11,
 | 
						|
                                                              textAlign:
 | 
						|
                                                                  TextAlign
 | 
						|
                                                                      .center,
 | 
						|
                                                            ),
 | 
						|
                                                          )),
 | 
						|
                                                    ],
 | 
						|
                                                  ),
 | 
						|
                                                  AppText(item.clinicName,
 | 
						|
                                                      fontSize: 12,
 | 
						|
                                                      color: Colors.black,
 | 
						|
                                                      fontWeight:
 | 
						|
                                                          FontWeight.bold,
 | 
						|
                                                      textAlign: TextAlign.end),
 | 
						|
                                                ],
 | 
						|
                                              );
 | 
						|
                                            }).toList();
 | 
						|
                                          },
 | 
						|
                                          onChanged: (newValue) async {
 | 
						|
                                            clinicId = newValue;
 | 
						|
                                            GifLoaderDialogUtils.showMyDialog(
 | 
						|
                                                context);
 | 
						|
                                            await model.changeClinic(newValue,
 | 
						|
                                                authenticationViewModel);
 | 
						|
                                            GifLoaderDialogUtils.hideDialog(
 | 
						|
                                                context);
 | 
						|
                                            if (model.state ==
 | 
						|
                                                ViewState.ErrorLocal) {
 | 
						|
                                              DrAppToastMsg.showErrorToast(
 | 
						|
                                                  model.error);
 | 
						|
                                            }
 | 
						|
                                          },
 | 
						|
                                          items: projectsProvider
 | 
						|
                                              .doctorClinicsList
 | 
						|
                                              .map((item) {
 | 
						|
                                            return DropdownMenuItem(
 | 
						|
                                              child: AppText(
 | 
						|
                                                item.clinicName,
 | 
						|
                                                textAlign: TextAlign.left,
 | 
						|
                                              ),
 | 
						|
                                              value: item.clinicID,
 | 
						|
                                            );
 | 
						|
                                          }).toList(),
 | 
						|
                                        )),
 | 
						|
                                      ],
 | 
						|
                                    )
 | 
						|
                                  : AppText(
 | 
						|
                                      TranslationBase.of(context).noClinic),
 | 
						|
                            ),
 | 
						|
                          ],
 | 
						|
                        ),
 | 
						|
                        isClinic: true,
 | 
						|
                        height: 50,
 | 
						|
                      ),
 | 
						|
                    ])
 | 
						|
                  ])),
 | 
						|
              content: Column(
 | 
						|
                children: [
 | 
						|
                  model.dashboardItemsList.length > 0
 | 
						|
                      ? DashboardSwipeWidget(
 | 
						|
                          model.dashboardItemsList,
 | 
						|
                          model,
 | 
						|
                          (sliderIndex) {
 | 
						|
                            setState(() {
 | 
						|
                              sliderActiveIndex = sliderIndex;
 | 
						|
                            });
 | 
						|
                          },
 | 
						|
                        )
 | 
						|
                      : SizedBox(),
 | 
						|
                  model.dashboardItemsList.length > 0
 | 
						|
                      ? FractionallySizedBox(
 | 
						|
                          widthFactor: 0.90,
 | 
						|
                          child: Container(
 | 
						|
                              child: Column(
 | 
						|
                                  mainAxisAlignment: MainAxisAlignment.start,
 | 
						|
                                  children: <Widget>[
 | 
						|
                                SizedBox(
 | 
						|
                                  height: 10,
 | 
						|
                                ),
 | 
						|
                                sliderActiveIndex == 1
 | 
						|
                                    ? DashboardSliderItemWidget(
 | 
						|
                                        model.dashboardItemsList[4])
 | 
						|
                                    : sliderActiveIndex == 0
 | 
						|
                                        ? DashboardSliderItemWidget(
 | 
						|
                                            model.dashboardItemsList[3])
 | 
						|
                                        : DashboardSliderItemWidget(
 | 
						|
                                            model.dashboardItemsList[6]),
 | 
						|
                              ])))
 | 
						|
                      : SizedBox(),
 | 
						|
                  FractionallySizedBox(
 | 
						|
                    // widthFactor: 0.90,
 | 
						|
                    child: Container(
 | 
						|
                      decoration: BoxDecoration(
 | 
						|
                          color: Colors.white,
 | 
						|
                          borderRadius: BorderRadius.only(
 | 
						|
                            topRight: Radius.circular(50),
 | 
						|
                          )),
 | 
						|
                      padding: EdgeInsets.only(left: 20, top: 10, right: 20),
 | 
						|
                      margin: EdgeInsets.only(top: 10),
 | 
						|
                      child: Column(
 | 
						|
                        mainAxisAlignment: MainAxisAlignment.start,
 | 
						|
                        crossAxisAlignment: CrossAxisAlignment.start,
 | 
						|
                        children: <Widget>[
 | 
						|
                          SizedBox(
 | 
						|
                            height: 10,
 | 
						|
                          ),
 | 
						|
                          Container(
 | 
						|
                              child: Column(
 | 
						|
                            mainAxisAlignment: MainAxisAlignment.center,
 | 
						|
                            crossAxisAlignment: CrossAxisAlignment.start,
 | 
						|
                            children: [
 | 
						|
                              AppText(
 | 
						|
                                TranslationBase.of(context).patients,
 | 
						|
                                fontSize: 12,
 | 
						|
                                fontWeight: FontWeight.bold,
 | 
						|
                                fontHeight: .5,
 | 
						|
                              ),
 | 
						|
                              AppText(
 | 
						|
                                TranslationBase.of(context).services,
 | 
						|
                                fontSize: 22,
 | 
						|
                                fontWeight: FontWeight.bold,
 | 
						|
                              ),
 | 
						|
                            ],
 | 
						|
                          )),
 | 
						|
                          SizedBox(
 | 
						|
                            height: 10,
 | 
						|
                          ),
 | 
						|
                          Container(
 | 
						|
                              height: 120,
 | 
						|
                              child: ListView(
 | 
						|
                                  scrollDirection: Axis.horizontal,
 | 
						|
                                  children: [
 | 
						|
                                    ...homePatientsCardsWidget(model),
 | 
						|
                                  ])),
 | 
						|
                          SizedBox(
 | 
						|
                            height: 20,
 | 
						|
                          ),
 | 
						|
                        ],
 | 
						|
                      ),
 | 
						|
                    ),
 | 
						|
                  ),
 | 
						|
                ],
 | 
						|
              ),
 | 
						|
            )
 | 
						|
          ]),
 | 
						|
        ]),
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  List<Widget> homePatientsCardsWidget(DashboardViewModel model) {
 | 
						|
    colorIndex = 0;
 | 
						|
 | 
						|
    List<Color> backgroundColors = List(3);
 | 
						|
    backgroundColors[0] = Color(0xffD02127);
 | 
						|
    backgroundColors[1] = Colors.grey[300];
 | 
						|
    backgroundColors[2] = Color(0xff2B353E);
 | 
						|
    List<Color> backgroundIconColors = List(3);
 | 
						|
    backgroundIconColors[0] = Colors.white12;
 | 
						|
    backgroundIconColors[1] = Colors.white38;
 | 
						|
    backgroundIconColors[2] = Colors.white10;
 | 
						|
    List<Color> textColors = List(3);
 | 
						|
    textColors[0] = Colors.white;
 | 
						|
    textColors[1] = Colors.black;
 | 
						|
    textColors[2] = Colors.white;
 | 
						|
 | 
						|
    List<HomePatientCard> patientCards = List();
 | 
						|
 | 
						|
    if (model.hasVirtualClinic) {
 | 
						|
      patientCards.add(HomePatientCard(
 | 
						|
        backgroundColor: backgroundColors[colorIndex],
 | 
						|
        backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
        cardIcon: DoctorApp.livecare,
 | 
						|
        textColor: textColors[colorIndex],
 | 
						|
        text:
 | 
						|
            "${TranslationBase.of(context).liveCare}\n${TranslationBase.of(context).patients}",
 | 
						|
        onTap: () {
 | 
						|
          Navigator.push(
 | 
						|
            context,
 | 
						|
            FadePage(
 | 
						|
              page: LiveCarePatientScreen(),
 | 
						|
            ),
 | 
						|
          );
 | 
						|
        },
 | 
						|
      ));
 | 
						|
      changeColorIndex();
 | 
						|
    }
 | 
						|
 | 
						|
    patientCards.add(HomePatientCard(
 | 
						|
      backgroundColor: backgroundColors[colorIndex],
 | 
						|
      backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
      cardIcon: DoctorApp.inpatient,
 | 
						|
      textColor: textColors[colorIndex],
 | 
						|
      text: TranslationBase.of(context).myInPatient,
 | 
						|
      onTap: () {
 | 
						|
        Navigator.push(
 | 
						|
          context,
 | 
						|
          FadePage(
 | 
						|
            page: PatientInPatientScreen(),
 | 
						|
          ),
 | 
						|
        );
 | 
						|
      },
 | 
						|
    ));
 | 
						|
    changeColorIndex();
 | 
						|
 | 
						|
    patientCards.add(HomePatientCard(
 | 
						|
      backgroundColor: backgroundColors[colorIndex],
 | 
						|
      backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
      cardIcon: DoctorApp.arrival_patients,
 | 
						|
      textColor: textColors[colorIndex],
 | 
						|
      text: TranslationBase.of(context).myOutPatient_2lines,
 | 
						|
      onTap: () {
 | 
						|
        String date = AppDateUtils.convertDateToFormat(
 | 
						|
            DateTime(
 | 
						|
                DateTime.now().year, DateTime.now().month, DateTime.now().day),
 | 
						|
            'yyyy-MM-dd');
 | 
						|
 | 
						|
        Navigator.push(
 | 
						|
            context,
 | 
						|
            MaterialPageRoute(
 | 
						|
              builder: (context) => OutPatientsScreen(
 | 
						|
                  patientSearchRequestModel: PatientSearchRequestModel(
 | 
						|
                      from: date,
 | 
						|
                      to: date,
 | 
						|
                      doctorID:
 | 
						|
                          authenticationViewModel.doctorProfile.doctorID)),
 | 
						|
            ));
 | 
						|
      },
 | 
						|
    ));
 | 
						|
    changeColorIndex();
 | 
						|
 | 
						|
    patientCards.add(HomePatientCard(
 | 
						|
      backgroundColor: backgroundColors[colorIndex],
 | 
						|
      backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
      cardIcon: DoctorApp.referral_1,
 | 
						|
      textColor: textColors[colorIndex],
 | 
						|
      text: TranslationBase.of(context)
 | 
						|
          .myPatientsReferral,
 | 
						|
      onTap: () {
 | 
						|
        Navigator.push(
 | 
						|
          context,
 | 
						|
          MaterialPageRoute(
 | 
						|
            builder: (context) =>
 | 
						|
                PatientReferralScreen(),
 | 
						|
          ),
 | 
						|
        );
 | 
						|
      },
 | 
						|
    ));
 | 
						|
    changeColorIndex();
 | 
						|
 | 
						|
    patientCards.add(HomePatientCard(
 | 
						|
      backgroundColor: backgroundColors[colorIndex],
 | 
						|
      backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
      cardIcon: DoctorApp.search,
 | 
						|
      textColor: textColors[colorIndex],
 | 
						|
      text: TranslationBase.of(context)
 | 
						|
          .searchPatientDashBoard,
 | 
						|
      onTap: () {
 | 
						|
        Navigator.push(
 | 
						|
            context,
 | 
						|
            MaterialPageRoute(
 | 
						|
              builder: (context) =>
 | 
						|
                  PatientSearchScreen(),
 | 
						|
            ));
 | 
						|
      },
 | 
						|
    ));
 | 
						|
    changeColorIndex();
 | 
						|
 | 
						|
    patientCards.add(HomePatientCard(
 | 
						|
      backgroundColor: backgroundColors[colorIndex],
 | 
						|
      backgroundIconColor: backgroundIconColors[colorIndex],
 | 
						|
      cardIcon: DoctorApp.search_medicines,
 | 
						|
      textColor: textColors[colorIndex],
 | 
						|
      text: TranslationBase.of(context)
 | 
						|
          .searchMedicineDashboard,
 | 
						|
      onTap: () {
 | 
						|
        Navigator.push(
 | 
						|
            context,
 | 
						|
            MaterialPageRoute(
 | 
						|
              builder: (context) =>
 | 
						|
                  MedicineSearchScreen(),
 | 
						|
            ));
 | 
						|
      },
 | 
						|
    ));
 | 
						|
    changeColorIndex();
 | 
						|
 | 
						|
    return [
 | 
						|
      ...List.generate(patientCards.length, (index) => patientCards[index])
 | 
						|
          .toList()
 | 
						|
    ];
 | 
						|
  }
 | 
						|
 | 
						|
  changeColorIndex() {
 | 
						|
    colorIndex++;
 | 
						|
    if (colorIndex > 2) {
 | 
						|
      colorIndex = 0;
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |