import 'package:diplomaticquarterapp/analytics/google-analytics.dart';
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/service/medical/vital_sign_service.dart';
import 'package:diplomaticquarterapp/core/service/privilege_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/appointment_rate_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart';
import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart';
import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notifications_page.dart';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/pages/rateAppointment/rate_appointment_doctor.dart';
import 'package:diplomaticquarterapp/pages/webRTC/call_page.dart';
import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/theme/theme_notifier.dart';
import 'package:diplomaticquarterapp/theme/theme_value.dart';
import 'package:diplomaticquarterapp/uitl/HMGNetworkConnectivity.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:in_app_review/in_app_review.dart';
import 'package:provider/provider.dart';

import '../../config/size_config.dart';
import '../../locator.dart';
import 'drawer_item_widget.dart';

class AppDrawer extends StatefulWidget {
  @override
  _AppDrawerState createState() => _AppDrawerState();
}

class _AppDrawerState extends State<AppDrawer> {
  final InAppReview _inAppReview = InAppReview.instance;

  @override
  void initState() {
    super.initState();
    checkUserData();
  }

  ProjectViewModel projectProvider;
  var sharedPref = new AppSharedPreferences();
  var familyFileProvider = FamilyFilesProvider();
  PharmacyModuleViewModel pharmacyModuleViewModel = locator<PharmacyModuleViewModel>();
  AuthenticatedUser user;
  AuthenticatedUser mainUser;
  AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
  VitalSignService _vitalSignService = locator<VitalSignService>();
  AppointmentRateViewModel appointmentRateViewModel = locator<AppointmentRateViewModel>();
  PrivilegeService _privilegeService = locator<PrivilegeService>();
  ToDoCountProviderModel toDoProvider;
  String booldType;
  String notificationCount;
  final authService = new AuthProvider();

  @override
  Widget build(BuildContext context) {
    projectProvider = Provider.of(context);
    toDoProvider = Provider.of<ToDoCountProviderModel>(context);
    return Container(
        width: MediaQuery.of(context).size.width * 0.75,
        color: Theme.of(context).scaffoldBackgroundColor,
        child: Container(
          color: Colors.white,
          child: Theme(
            data: Theme.of(context).copyWith(canvasColor: Theme.of(context).scaffoldBackgroundColor),
            child: Drawer(
              child: Column(
                children: <Widget>[
                  Expanded(
                    child: ListView(
                      padding: EdgeInsets.zero,
                      children: <Widget>[
                        Container(
                          height: SizeConfig.screenHeight * .30,
                          child: InkWell(
                            child: Padding(
                              padding: const EdgeInsets.all(14.0),
                              child: Column(
                                children: <Widget>[
                                  Container(
                                    width: double.infinity,
                                    padding: EdgeInsets.only(top: 12),
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        SvgPicture.asset(
                                          "assets/images/new/logo.svg",
                                          height: 60,
                                          width: 60,
                                        ),
                                        IconButton(
                                          icon: Icon(Icons.clear),
                                          onPressed: () {
                                            Navigator.pop(context);
                                          },
                                        )
                                      ],
                                    ),
                                  ),
                                  mHeight(12),
                                  Container(
                                    width: double.infinity,
                                    margin: EdgeInsets.only(top: 12),
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      mainAxisAlignment: MainAxisAlignment.start,
                                      children: [
                                        Text(
                                          (user != null && projectProvider.isLogin) ? user.firstName + ' ' + user.lastName : TranslationBase.of(context).cantSeeProfile,
                                          style: TextStyle(color: Color(0xff2E303A), fontWeight: FontWeight.bold, fontSize: 20, letterSpacing: -1.2, height: 35 / 20),
                                        ),
                                        Text(
                                          (user != null && projectProvider.isLogin)
                                              ? TranslationBase.of(context).fileNumber + ": " + user.patientID.toString()
                                              : TranslationBase.of(context).loginRegisterNow,
                                          style: TextStyle(
                                            color: Color(0xff2E303A),
                                            fontSize: 16,
                                            letterSpacing: -0.96,
                                            height: 1,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Container(
                            child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            (user != null && projectProvider.isLogin)
                                ? Container()
                                : InkWell(
                                    child: DrawerItem(
                                      TranslationBase.of(context).arabicChange,
                                      Padding(child: Image.asset('assets/images/lang.png'), padding: EdgeInsets.all(3)),
                                      isImageIcon: true,
                                      bottomLine: false,
                                      projectProvider: projectProvider,
                                    ),
                                    onTap: () {
                                      sharedPref.setBool(IS_ROBOT_INIT, null);
                                      sharedPref.remove(CLINICS_LIST);
                                      if (projectProvider.isArabic) {
                                        projectProvider.changeLanguage('en');
                                        locator<GAnalytics>().hamburgerMenu.logMenuItemClick('change language to english');
                                      } else {
                                        projectProvider.changeLanguage('ar');
                                        locator<GAnalytics>().hamburgerMenu.logMenuItemClick('change language to arabic');
                                      }
                                      var themeNotifier = Provider.of<ThemeNotifier>(context, listen: false);
                                      themeNotifier.setTheme(defaultTheme(fontName: projectProvider.isArabic ? 'Cairo' : 'Poppins'));
                                    },
                                  ),
                            (user != null && projectProvider.isLogin)
                                ? Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: <Widget>[
                                      (user.isFamily == null || user.isFamily == false)
                                          ? InkWell(
                                              child: DrawerItem(TranslationBase.of(context).family, SvgPicture.asset("assets/images/new/family_files.svg"),
                                                  isImageIcon: true,
                                                  bottomLine: false,
                                                  textColor: Theme.of(context).textTheme.bodyText1.color,
                                                  iconColor: Theme.of(context).textTheme.bodyText1.color,
                                                  sideArrow: true,
                                                  letterSpacing: -0.84,
                                                  projectProvider: projectProvider),
                                              onTap: () {
                                                Navigator.of(context).pop();
                                                Navigator.of(context).pushNamed(
                                                  MY_FAMILIY,
                                                );

                                                locator<GAnalytics>().hamburgerMenu.logMenuItemClick('my family');
                                              },
                                            )
                                          : SizedBox(),
                                      FutureBuilder(
                                        future: getFamilyFiles(), // async work
                                        builder: (BuildContext context, AsyncSnapshot<GetAllSharedRecordsByStatusResponse> snapshot) {
                                          switch (snapshot.connectionState) {
                                            case ConnectionState.waiting:
                                              return Padding(padding: EdgeInsets.all(10), child: Text(''));
                                            default:
                                              if (snapshot.hasError)
                                                return Padding(padding: EdgeInsets.all(10), child: Text(snapshot.error));
                                              else
                                                return Container(
                                                    child: Column(
                                                  children: [
                                                    user.isFamily == true
                                                        ? Container(
                                                            padding: EdgeInsets.only(bottom: 5, left: 4),
                                                            child: InkWell(
                                                              onTap: () {
                                                                switchUser(mainUser, context);
                                                              },
                                                              child: Row(
                                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                                children: <Widget>[
                                                                  Expanded(
                                                                    child: SvgPicture.asset("assets/images/new/family_files.svg"),
                                                                  ),
                                                                  Expanded(
                                                                    flex: 7,
                                                                    child: Column(
                                                                      crossAxisAlignment: CrossAxisAlignment.start,
                                                                      children: <Widget>[
                                                                        AppText(
                                                                          mainUser.firstName + ' ' + mainUser.lastName,
                                                                          color: Color(0xff2E303A), //Theme.of(context).textTheme.bodyText1.color,
                                                                          fontWeight: FontWeight.w600,
                                                                          fontSize: 12,
                                                                          letterSpacing: -0.33,
                                                                        ),
                                                                        AppText(
                                                                          TranslationBase.of(context).fileno + ": " + mainUser.patientID.toString(),
                                                                          color: Color(0xff989898),
                                                                          fontSize: 12,
                                                                          letterSpacing: -0.33,
                                                                        ),
                                                                        Container(
                                                                          height: 1,
                                                                          margin: EdgeInsets.only(top: 7.5),
                                                                          color: Color(0xffEDEDED),
                                                                        ),
                                                                      ],
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                            ),
                                                          )
                                                        : SizedBox(),
                                                    Column(
                                                        mainAxisAlignment: MainAxisAlignment.start,
                                                        mainAxisSize: MainAxisSize.min,
                                                        children: snapshot.data.getAllSharedRecordsByStatusList.map<Widget>((result) {
                                                          return result.status == 3
                                                              ? Container(
                                                                  padding: EdgeInsets.only(bottom: 5),
                                                                  child: InkWell(
                                                                    onTap: () {
                                                                      switchUser(result, context);
                                                                    },
                                                                    child: Row(
                                                                      crossAxisAlignment: CrossAxisAlignment.start,
                                                                      children: <Widget>[
                                                                        Expanded(
                                                                          child: Icon(Icons.person, color: result.responseID == user.patientID ? Colors.transparent : Colors.transparent),
                                                                        ),
                                                                        Expanded(
                                                                          flex: 7,
                                                                          child: Padding(
                                                                            padding: EdgeInsets.only(left: 5, right: 5),
                                                                            child: Column(
                                                                              crossAxisAlignment: CrossAxisAlignment.start,
                                                                              children: <Widget>[
                                                                                AppText(
                                                                                  result.patientName,
                                                                                  color: result.responseID == user.patientID ? Color(0xffC5272D) : Color(0xff2B353E),
                                                                                  fontWeight: FontWeight.w600,
                                                                                  fontSize: 11,
                                                                                  letterSpacing: -0.33,
                                                                                ),
                                                                                AppText(
                                                                                  TranslationBase.of(context).fileno + ": " + result.responseID.toString(),
                                                                                  color: result.responseID == user.patientID ? Color(0xffC5272D) : Color(0xff989898),
                                                                                  fontSize: 11,
                                                                                  letterSpacing: -0.33,
                                                                                ),
                                                                                Divider(
                                                                                  color: Colors.grey[400],
                                                                                ),
                                                                              ],
                                                                            ),
                                                                          ),
                                                                        ),
                                                                      ],
                                                                    ),
                                                                  ),
                                                                )
                                                              : SizedBox();
                                                        }).toList())
                                                  ],
                                                ));
                                          }
                                        },
                                      ),
                                      mHeight(20),
                                      InkWell(
                                        child: DrawerItem(TranslationBase.of(context).arabicChange,
                                            Padding(child: Image.asset('assets/images/lang.png'), padding: EdgeInsets.only(left: 3, right: 3, top: 3, bottom: projectProvider.isArabic ? 3 : 0)),
                                            isImageIcon: true, bottomLine: false, letterSpacing: -0.84, fontSize: 14, fontHeight: projectProvider.isArabic ? 1 : 0.8, projectProvider: projectProvider),
                                        onTap: () {
                                          sharedPref.remove(APPOINTMENT_HISTORY_MEDICAL);
                                          sharedPref.remove(CLINICS_LIST);
                                          sharedPref.setBool(IS_ROBOT_INIT, null);
                                          if (projectProvider.isArabic) {
                                            projectProvider.changeLanguage('en');
                                            locator<GAnalytics>().hamburgerMenu.logMenuItemClick('change language to english');
                                          } else {
                                            projectProvider.changeLanguage('ar');
                                            locator<GAnalytics>().hamburgerMenu.logMenuItemClick('change language to arabic');
                                          }
                                        },
                                      ),
                                      InkWell(
                                        child: Stack(
                                          children: [
                                            DrawerItem(
                                              TranslationBase.of(context).notification,
                                              SvgPicture.asset("assets/images/new/notifications.svg"),
                                              isImageIcon: true,
                                              bottomLine: false,
                                              letterSpacing: -0.84,
                                              fontSize: 14,
                                              projectProvider: projectProvider,
                                              count: toDoProvider.notificationsCount != "0" && !projectProvider.isLoginChild
                                                  ? new Container(
                                                      padding: EdgeInsets.all(4),
                                                      margin: EdgeInsets.all(2),
                                                      decoration: new BoxDecoration(
                                                        color: CustomColors.accentColor,
                                                        borderRadius: BorderRadius.circular(20),
                                                      ),
                                                      constraints: BoxConstraints(
                                                        minWidth: 20,
                                                        minHeight: 20,
                                                      ),
                                                      child: new Text(
                                                        toDoProvider.notificationsCount.toString(),
                                                        style: new TextStyle(
                                                          color: Colors.white,
                                                          fontSize: projectProvider.isArabic ? 8 : 9,
                                                        ),
                                                        textAlign: TextAlign.center,
                                                      ),
                                                      //   ),
                                                    )
                                                  : SizedBox(),
                                            ),
                                          ],
                                        ),
                                        onTap: () {
                                          //NotificationsPage
                                          // Navigator.of(context).pop();
                                          if (!projectProvider.isLoginChild) Navigator.push(context, FadePage(page: NotificationsPage()));
                                          locator<GAnalytics>().hamburgerMenu.logMenuItemClick('notifications');
                                        },
                                      ),
                                      if (projectProvider.havePrivilege(3))
                                        InkWell(
                                          child: DrawerItem(TranslationBase.of(context).appsetting, SvgPicture.asset("assets/images/new/app_setting.svg"),
                                              isImageIcon: true, bottomLine: false, letterSpacing: -0.84, fontSize: 14, projectProvider: projectProvider),
                                          onTap: () {
                                            Navigator.of(context).pushNamed(
                                              SETTINGS,
                                            );
                                            locator<GAnalytics>().hamburgerMenu.logMenuItemClick('app settings');
                                          },
                                        ),
                                      InkWell(
                                        child: DrawerItem(TranslationBase.of(context).rateApp, Icons.star, bottomLine: false, letterSpacing: -0.84, fontSize: 14, projectProvider: projectProvider),
                                        onTap: () {
                                          locator<GAnalytics>().hamburgerMenu.logMenuItemClick('rate our app');
                                          openAppReviewDialog();
                                          // if (Platform.isIOS) {
                                          //   launch("https://apps.apple.com/sa/app/dr-suliaman-alhabib/id733503978");
                                          // } else {
                                          //   launch("https://play.google.com/store/apps/details?id=com.ejada.hmg&hl=en");
                                          // }
                                        },
                                      ),
                                      InkWell(
                                        child: DrawerItem(TranslationBase.of(context).logout, SvgPicture.asset("assets/images/new/logout.svg"),
                                            isImageIcon: true, bottomLine: false, letterSpacing: -0.84, fontSize: 14, projectProvider: projectProvider),
                                        onTap: () {
                                          logout();
                                        },
                                      )
                                    ],
                                  )
                                : InkWell(
                                    child: DrawerItem(TranslationBase.of(context).loginregister, SvgPicture.asset("assets/images/new/logout.svg"),
                                        isImageIcon: true, letterSpacing: -0.84, fontSize: 14, bottomLine: false, projectProvider: projectProvider),
                                    onTap: () {
                                      login();
                                    },
                                  ),
                            // InkWell(
                            //   child: DrawerItem(
                            //       TranslationBase.of(context).appsetting,
                            //       Icons.settings_input_composite),
                            //   onTap: () {
                            //     Navigator.of(context).pushNamed(
                            //       SETTINGS,
                            //     );
                            //   },
                            // )
                          ],
                        ))
                      ],
                    ),
                  ),
                  mHeight(12),
                  InkWell(
                    onTap: () {
                      Navigator.push(context, FadePage(page: CallPage()));
                      locator<GAnalytics>().hamburgerMenu.logMenuItemClick('cloud solution logo tap');
                      GifLoaderDialogUtils.showMyDialog(context);
                      HMGNetworkConnectivity(context).start();
                    },
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          TranslationBase.of(context).poweredBy,
                          style: TextStyle(
                            color: Color(0xFF989898),
                            fontSize: 13,
                            letterSpacing: -0.54,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        mWidth(2),
                        Text(
                          "Cloud Solutions",
                          style: TextStyle(
                            color: Color(0xff2E303A),
                            fontSize: 13,
                            letterSpacing: -0.54,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        mWidth(16),
                        SvgPicture.asset("assets/images/new/cloud_logo.svg"),
                      ],
                    ),
                  ),
                  mHeight(12),
                ],
              ),
            ),
          ),
        ));
  }

  drawerNavigator(context, routeName) {
    Navigator.of(context).pushNamed(routeName);
  }

  checkUserData() async {
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));

      var data2 = AuthenticatedUser.fromJson(await this.sharedPref.getObject(MAIN_USER));

      setState(() {
        this.user = data;
        this.mainUser = data2;
      });
    }
    notificationCount = await sharedPref.getString(NOTIFICATION_COUNT);
  }

  logout() async {
    ConfirmDialog dialog = new ConfirmDialog(
        context: context,
        confirmMessage: TranslationBase.of(context).signoutMessage,
        okText: TranslationBase.of(context).confirm,
        cancelText: TranslationBase.of(context).cancel_nocaps,
        okFunction: () async {
          authenticatedUserObject.logout();
          projectProvider.isLogin = false;
          await authenticatedUserObject.getUser();
          _vitalSignService.heightCm = "";
          _vitalSignService.weightKg = "";
          await _privilegeService.getPrivilege();
          projectProvider.setPrivilegeModelList(privilege: _privilegeService.privilegeModelList);
          var appLanguage = await sharedPref.getString(APP_LANGUAGE);
          await sharedPref.clear();
          await sharedPref.setString(APP_LANGUAGE, appLanguage);
          await sharedPref.remove(APPOINTMENT_HISTORY_MEDICAL);
          this.user = null;
          Navigator.of(context).pushNamed(HOME);
          locator<GAnalytics>().hamburgerMenu.logMenuItemClick('logout');
        },
        cancelFunction: () => {});
    dialog.showAlertDialog(context);
  }

  login() async {
    locator<GAnalytics>().hamburgerMenu.logMenuItemClick('login');
    var data = await sharedPref.getObject(IMEI_USER_DATA);
    sharedPref.remove(REGISTER_DATA_FOR_LOGIIN);

    locator<GAnalytics>().loginRegistration.login_register_initiate();
    if (data != null) {
      Navigator.of(context).pushNamed(CONFIRM_LOGIN);
    } else {
      GifLoaderDialogUtils.showMyDialog(context);
      authService.selectDeviceImei(DEVICE_TOKEN).then((SelectDeviceIMEIRES value) {
        GifLoaderDialogUtils.hideDialog(context);
        if (value != null) {
          setUserValues(value);
          Navigator.of(context).pushNamed(CONFIRM_LOGIN);
        } else {
          Navigator.of(context).pushNamed(
            WELCOME_LOGIN,
          );
        }
      }).catchError((err) {
        GifLoaderDialogUtils.hideDialog(context);
        Navigator.of(context).pushNamed(
          WELCOME_LOGIN,
        );
      });
    }
  }

  Future<GetAllSharedRecordsByStatusResponse> getFamilyFiles() async {
    if (user != null) {
      if (await sharedPref.getObject(FAMILY_FILE) != null) {
        // print(await sharedPref.getObject(FAMILY_FILE));
        return Future.value(GetAllSharedRecordsByStatusResponse.fromJson(await sharedPref.getObject(FAMILY_FILE)));
      } else {
        return familyFileProvider.getSharedRecordByStatus();
      }
    }
  }

  switchUser(user, context) {
    GifLoaderDialogUtils.showMyDialog(context);
    this.familyFileProvider.silentLoggin(user is AuthenticatedUser ? null : user, mainUser: user is AuthenticatedUser).then((value) {
      // GifLoaderDialogUtils.hideDialog(context);
      // Navigator.of(context).pop();
      loginAfter(value, context, user is AuthenticatedUser);
      locator<GAnalytics>().hamburgerMenu.logMenuItemClick('switch to my family account');
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
      AppToast.showErrorToast(message: err);
      Navigator.of(context).pop();
    });
  }

  loginAfter(result, context, isMainUser) async {
    Utils.hideProgressDialog();
    Provider.of<ProjectViewModel>(context, listen: false).setPrivilege(privilegeList: result, isLoginChild: !isMainUser);
    result = CheckActivationCode.fromJson(result);
    var bloodType = await sharedPref.getString(BLOOD_TYPE);
    var familyFile = await sharedPref.getObject(FAMILY_FILE);
    var currentLang = await sharedPref.getString(APP_LANGUAGE);
    var mainUser = await sharedPref.getObject(MAIN_USER);
    var loginType = await sharedPref.getInt(LAST_LOGIN);
    this.sharedPref.clear();
    if (mainUser["PatientID"] != result.list.patientID) {
      result.list.isFamily = true;
    } else {
      result.list.isFamily = false;
    }
    // result.list.cRSVerificationStatus = result['CRSVerificationStatus'];
    this.sharedPref.setString(APP_LANGUAGE, currentLang);
    this.sharedPref.setString(BLOOD_TYPE, bloodType);
    this.sharedPref.setInt(LAST_LOGIN, loginType);
    this.sharedPref.setObject(MAIN_USER, mainUser);
    this.sharedPref.setObject(USER_PROFILE, result.list);
    this.sharedPref.setObject(FAMILY_FILE, familyFile);
    this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID);
    this.sharedPref.setString(TOKEN, result.authenticationTokenID);
    // Navigator.of(context).pop();
    // await authenticatedUserObject.getUser(getUser: true);
    Provider.of<ProjectViewModel>(context, listen: false).user = result.list;
    Provider.of<ProjectViewModel>(context, listen: false).setUser(result.list);
    // await pharmacyModuleViewModel.generatePharmacyToken();
    _vitalSignService.heightCm = "";
    _vitalSignService.weightKg = "";

    if (pharmacyModuleViewModel.error.isNotEmpty) await pharmacyModuleViewModel.createUser();

    appointmentRateViewModel
        .getIsLastAppointmentRatedList()
        .then((value) => {
              getToDoCount(),
              //Utils.hideProgressDialog(),
              if (appointmentRateViewModel.isHaveAppointmentNotRate)
                {
                  Navigator.pushAndRemoveUntil(
                      context,
                      FadePage(
                        page: RateAppointmentDoctor(),
                      ),
                      (r) => false)
                }
              else
                {
                  Navigator.pushAndRemoveUntil(
                      context,
                      FadePage(
                        page: LandingPage(),
                      ),
                      (r) => false)
                }
            })
        .catchError((err) {
      print(err);
      //Utils.hideProgressDialog();
      // GifLoaderDialogUtils.hideDialog(context);
    });
  }

  openAppReviewDialog() async {
    if (await _inAppReview.isAvailable()) {
      _inAppReview.requestReview();
    }
  }

  void setUserValues(value) async {
    if (value != null) sharedPref.setObject(IMEI_USER_DATA, value);
  }

  getToDoCount() {
    toDoProvider.setState(0, true, toDoProvider.notificationsCount);
    ClinicListService service = new ClinicListService();
    service.getActiveAppointmentNo(context).then((res) {
      print(res['AppointmentActiveNumber']);
      if (res['MessageStatus'] == 1 && res['AppointmentActiveNumber'] != null) {
        toDoProvider.setState(res['AppointmentActiveNumber'], true, toDoProvider.notificationsCount);
      } else {}
    }).catchError((err) {
      print(err);
    });
  }
}
