import 'dart:ui';

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/service/medical/vital_sign_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/locator.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart'
    as list;
import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/BranchView.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/pages/rateAppointment/rate_appointment_doctor.dart';
import 'package:diplomaticquarterapp/services/family_files/family_files_provider.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/widgets/card/rounded_container.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/bottom_bar.dart';
import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/routes.dart';
import 'package:provider/provider.dart';

class MyFamily extends StatefulWidget {
  final bool isAppbarVisible;
  MyFamily({this.isAppbarVisible = true});
  @override
  _MyFamily createState() => _MyFamily();
}

class _MyFamily extends State<MyFamily> with TickerProviderStateMixin {
  List<ImagesInfo> imagesInfo = List();
  final familyFileProvider = FamilyFilesProvider();
  AppSharedPreferences sharedPref = new AppSharedPreferences();
  var userID;
  TabController _tabController;
  int _tabIndex = 0;
  AuthenticatedUserObject authenticatedUserObject =
      locator<AuthenticatedUserObject>();
  AppointmentRateViewModel appointmentRateViewModel =
      locator<AppointmentRateViewModel>();
  ProjectViewModel projectViewModel;
  AuthenticatedUser user;
  VitalSignService _vitalSignService = locator<VitalSignService>();
  PharmacyModuleViewModel pharmacyModuleViewModel =
      locator<PharmacyModuleViewModel>();

  var isVaiable = false;
  @override
  void initState() {
    _tabController = new TabController(length: 2, vsync: this, initialIndex: 0);
    checkUserData();
    super.initState();
  }

  bool expandFlag = false;

  Widget build(BuildContext context) {
    imagesInfo.add(
      ImagesInfo(
          imageEn:
              'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png',
          imageAr:
              'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'),
    );

    imagesInfo.add(
      ImagesInfo(
          imageEn:
              'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png',
          imageAr:
              'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'),
    );
    projectViewModel = Provider.of(context);
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).myFamilyFiles,
      isShowAppBar: widget.isAppbarVisible,
      imagesInfo: imagesInfo,
      description: TranslationBase.of(context).familyInfo,
      body: Scaffold(
        extendBodyBehindAppBar: true,
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(65.0),
          child: Stack(
            children: <Widget>[
              Positioned(
                bottom: 1,
                left: 0,
                right: 0,
                child: BackdropFilter(
                  filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
                  child: Container(
                    color: Theme.of(context)
                        .scaffoldBackgroundColor
                        .withOpacity(0.8),
                    height: 70.0,
                  ),
                ),
              ),
              Center(
                child: Container(
                  height: 60.0,
                  margin: EdgeInsets.only(top: 10.0),
                  width: MediaQuery.of(context).size.width * 0.92, // 0.9,
                  decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                            color: Theme.of(context).dividerColor,
                            width: 0.9), //width: 0.7
                      ),
                      color: Colors.white),
                  child: Center(
                    child: TabBar(
                      isScrollable: true,
                      controller: _tabController,
                      indicatorWeight: 5.0,
                      //indicatorSize: TabBarIndicatorSize.label,
                      indicatorSize: TabBarIndicatorSize.tab,

                      indicatorColor: Theme.of(context).primaryColor,
                      labelColor: Theme.of(context).primaryColor,
                      labelPadding:
                          EdgeInsets.only(top: 4.0, left: 35.0, right: 35.0),
                      unselectedLabelColor: Colors.grey[800],
                      tabs: [
                        Container(
                          width: MediaQuery.of(context).size.width * 0.30,
                          child: Center(
                            child: AppText(TranslationBase.of(context).family),
                          ),
                        ),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.30,
                          child: Center(
                            child: AppText(TranslationBase.of(context).request),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        body: Column(
          children: <Widget>[
            Expanded(
              child: (user != null && projectViewModel.isLogin)
                  ? TabBarView(
                      physics: BouncingScrollPhysics(),
                      controller: _tabController,
                      children: [
                        myFamilyDetails(context),
                        myFamilyRequest(context)
                      ],
                    )
                  : Container(child: AppText('Loading..')),
            )
          ],
        ),
      ),
    );

    // return AppScaffold(
    //     appBarTitle: TranslationBase.of(context).myFamilyFiles,
    //     isShowAppBar: widget.isAppbarVisible,
    //     body: SingleChildScrollView(
    //         child: Container(
    //             height: SizeConfig.screenHeight * .9,
    //             width: SizeConfig.realScreenWidth,
    //             padding: EdgeInsets.all(20),
    //             child: Stack(
    //               children: <Widget>[
    //                 TabBar(
    //                   controller: _tabController,
    //                   indicatorColor: Colors.red,
    //                   tabs: [
    //                     Tab(
    //                         // padding: EdgeInsets.all(6),
    //                         child: AppText(TranslationBase.of(context).family)),
    //                     Tab(
    //                         // padding: EdgeInsets.all(6),
    //                         child:
    //                             AppText(TranslationBase.of(context).request)),
    //                   ],
    //                 ),
    //                 TabBarView(
    //                   controller: _tabController,
    //                   children: [
    //                     myFamilyDetails(context),
    //                     myFamilyRequest(context)
    //                   ],
    //                 )
    //               ],
    //             ))));
  }

  Widget myFamilyDetails(context) {
    return Container(
        height: MediaQuery.of(context).size.height,
        margin: EdgeInsets.fromLTRB(20.0, 25.0, 20.0, 0.0),
        child: Column(
          children: <Widget>[
            Expanded(
              flex: 4,
              child: FutureBuilder(
                future: getFamilyFiles(), // async work
                builder: (BuildContext context,
                    AsyncSnapshot<GetAllSharedRecordsByStatusResponse>
                        snapshot) {
                  switch (snapshot.connectionState) {
                    case ConnectionState.waiting:
                      return Padding(
                          padding: EdgeInsets.only(top: 50),
                          child: Text('Loading....'));
                    default:
                      if (snapshot.hasError)
                        return Padding(
                            padding: EdgeInsets.all(10),
                            child: Text(
                                TranslationBase.of(context).noDataAvailable));
                      else
                        return Padding(
                            padding: EdgeInsets.only(top: 50),
                            child: Column(children: <Widget>[
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  Expanded(
                                      flex: 3,
                                      child: Text(
                                          TranslationBase.of(context).request)),
                                  Expanded(
                                      flex: 2,
                                      child: Text(
                                        TranslationBase.of(context).switchUser,
                                      )),
                                  Expanded(
                                      flex: 1,
                                      child: Text(
                                        TranslationBase.of(context).deleteView,
                                      )),
                                ],
                              ),
                              Column(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: snapshot
                                      .data.getAllSharedRecordsByStatusList
                                      .map<Widget>((result) {
                                    return result.status == 3
                                        ? Padding(
                                            padding: EdgeInsets.all(10),
                                            child: Row(
                                              children: <Widget>[
                                                Expanded(
                                                    flex: 3,
                                                    child: Text(
                                                        result.patientName)),
                                                Expanded(
                                                    flex: 2,
                                                    child: IconButton(
                                                      icon: Icon(Icons.group),
                                                      color: Colors.black,
                                                      onPressed: () {
                                                        switchUser(
                                                            result, context);
                                                      },
                                                    )),
                                                Expanded(
                                                    flex: 1,
                                                    child: IconButton(
                                                      icon: Icon(
                                                        Icons.delete,
                                                        color: Colors.black,
                                                      ),
                                                      onPressed: () {
                                                        deleteFamily(
                                                            result, context);
                                                      },
                                                    )),
                                              ],
                                            ))
                                        : SizedBox();
                                  }).toList())
                            ]));
                  }
                },
              ),
            ),
            Expanded(
              flex: 1,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Expanded(
                          child: DefaultButton(
                        TranslationBase.of(context).addFamilyMember,
                        () => {
                          Navigator.of(context)
                              .pushNamed(ADD_FAMILY_MEMBER_TYPE)
                        },
                        color: Colors.grey[900],
                        textColor: Colors.white,
                      ))
                    ],
                  ),
                ],
              ),
            )
          ],
        ));
  }

  Widget myFamilyRequest(context) {
    return //Padding(
        // padding: const EdgeInsets.symmetric(horizontal: 10.0),
        // child:
        SingleChildScrollView(
      child: Container(
        height: MediaQuery.of(context).size.height,
        margin: EdgeInsets.only(top: 65),
        child: Column(
          children: <Widget>[
            RoundedContainer(
              child: ExpansionTile(
                title: Text(
                  TranslationBase.of(context).userViewRequest,
                  style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
                ),
                children: <Widget>[
                  FutureBuilder(
                      future: getUserViewRequest(), // async work
                      builder: (BuildContext context,
                          AsyncSnapshot<dynamic> snapshot) {
                        switch (snapshot.connectionState) {
                          case ConnectionState.waiting:
                            return Padding(
                                padding: EdgeInsets.only(top: 50),
                                child: Text('Loading....'));
                          default:
                            if (snapshot.hasError)
                              return Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Text(TranslationBase.of(context)
                                      .noDataAvailable));
                            else
                              return Column(
                                children: [
                                  // Padding(padding: EdgeInsets.only(left:10, right:10),
                                  // child:
                                  // Row(
                                  //   mainAxisAlignment:
                                  //       MainAxisAlignment.spaceBetween,
                                  //   children: <Widget>[
                                  //     Expanded(
                                  //         flex: 3,
                                  //         child: Text(TranslationBase.of(context)
                                  //             .request)),
                                  //     Expanded(
                                  //         flex: 2,
                                  //         child: Text(
                                  //           TranslationBase.of(context)
                                  //               .switchUser,
                                  //         )),
                                  //     Expanded(
                                  //         flex: 1,
                                  //         child: Text(
                                  //           TranslationBase.of(context)
                                  //               .deleteView,
                                  //         )),
                                  //   ],
                                  // )),
                                  Column(children: [
                                    Padding(
                                        padding: EdgeInsets.only(
                                            left: 10, right: 10),
                                        child: Row(children: [
                                          Expanded(
                                              flex: 3,
                                              child: AppText(
                                                  TranslationBase.of(context)
                                                      .name)),
                                          Expanded(
                                              flex: 1,
                                              child: AppText(
                                                  TranslationBase.of(context)
                                                      .allow)),
                                          Expanded(
                                              flex: 1,
                                              child: AppText(
                                                  TranslationBase.of(context)
                                                      .reject)),
                                        ])),
                                    Column(
                                        children: familyFileProvider
                                            .allSharedRecordsByStatusResponse
                                            .getAllSharedRecordsByStatusList
                                            .map<Widget>((result) {
                                      return Padding(
                                          padding: EdgeInsets.all(10),
                                          child: Row(
                                            children: <Widget>[
                                              Expanded(
                                                  flex: 3,
                                                  child:
                                                      Text(result.patientName)),
                                              Expanded(
                                                  flex: 1,
                                                  child: IconButton(
                                                    icon: Icon(
                                                      Icons.check_circle,
                                                      color: Colors.black,
                                                    ),
                                                    onPressed: () {
                                                      acceptRemoveRequest(
                                                          result.iD,
                                                          3,
                                                          context);
                                                    },
                                                  )),
                                              Expanded(
                                                  flex: 1,
                                                  child: IconButton(
                                                    icon: Icon(
                                                      Icons.delete,
                                                      color: Colors.black,
                                                    ),
                                                    onPressed: () {
                                                      acceptRemoveRequest(
                                                          result.iD,
                                                          4,
                                                          context);
                                                    },
                                                  ))
                                            ],
                                          ));
                                    }).toList())
                                  ])
                                ],
                              );
                        }
                      })
                ],
              ),
            ),
            RoundedContainer(
                child: ExpansionTile(
              title: Text(
                TranslationBase.of(context).sentRequest,
                style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
              ),
              children: <Widget>[
                FutureBuilder(
                    future: getSentRequest(), // async work
                    builder: (BuildContext context,
                        AsyncSnapshot<GetAllSharedRecordsByStatusResponse>
                            snapshot) {
                      switch (snapshot.connectionState) {
                        case ConnectionState.waiting:
                          return Padding(
                              padding: EdgeInsets.only(top: 50),
                              child: Text('Loading....'));
                        default:
                          if (snapshot.hasError)
                            return Padding(
                                padding: EdgeInsets.all(10),
                                child: Text(TranslationBase.of(context)
                                    .noDataAvailable));
                          else
                            return Container(
                                height: SizeConfig.screenHeight * .3,
                                child: SingleChildScrollView(
                                    child: Column(
                                  children: [
                                    Padding(
                                        padding: EdgeInsets.only(
                                            left: 10, right: 10),
                                        child: Row(children: [
                                          Expanded(
                                              flex: 3,
                                              child: AppText(
                                                  TranslationBase.of(context)
                                                      .theName))
                                        ])),
                                    Column(
                                      children: snapshot
                                          .data.getAllSharedRecordsByStatusList
                                          .map<Widget>((result) {
                                        return Padding(
                                            padding: EdgeInsets.all(10),
                                            child: Row(
                                              children: <Widget>[
                                                Expanded(
                                                    flex: 3,
                                                    child: Text(
                                                        result.patientName)),
                                                Expanded(
                                                    flex: 2,
                                                    child: AppText(
                                                      result.statusDescription,
                                                      color: result.status == 3
                                                          ? Colors.green
                                                          : Colors.red,
                                                    )),
                                              ],
                                            ));
                                      }).toList(),
                                    )
                                  ],
                                )));
                      }
                    })
              ],
            )),
            RoundedContainer(
                child: ExpansionTile(
              title: Text(
                TranslationBase.of(context).userView,
                style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
              ),
              children: <Widget>[
                FutureBuilder(
                    future: getUserViewRequest(), // async work
                    builder: (BuildContext context,
                        AsyncSnapshot<dynamic> snapshot) {
                      switch (snapshot.connectionState) {
                        case ConnectionState.waiting:
                          return Padding(
                              padding: EdgeInsets.only(top: 50),
                              child: Text('Loading....'));
                        default:
                          if (snapshot.hasError)
                            return Padding(
                                padding: EdgeInsets.all(10),
                                child: Text(TranslationBase.of(context)
                                    .noDataAvailable));
                          else
                            return Column(
                              children: [
                                // Padding(
                                //     padding:EdgeInsets.only(left:10, right:10),
                                //     child: Row(
                                //    mainAxisAlignment:
                                //        MainAxisAlignment.spaceBetween,
                                //    children: <Widget>[
                                //      Expanded(
                                //          flex: 3,
                                //          child: AppText(
                                //              TranslationBase.of(context).request),
                                //      ),
                                //      Expanded(
                                //          flex: 2,
                                //          child: AppText(
                                //            TranslationBase.of(context).switchUser,
                                //          )),
                                //      Expanded(
                                //          flex: 1,
                                //          child: AppText(
                                //            TranslationBase.of(context).deleteView,
                                //          )),
                                //    ],
                                //  )),
                                Column(children: [
                                  Padding(
                                      padding:
                                          EdgeInsets.only(left: 10, right: 10),
                                      child: Row(children: [
                                        Expanded(
                                            flex: 3,
                                            child: AppText(
                                                TranslationBase.of(context)
                                                    .name)),
                                        Expanded(
                                            flex: 1,
                                            child: AppText(
                                                TranslationBase.of(context)
                                                    .delete)),
                                      ])),
                                  Column(
                                      children: familyFileProvider
                                          .allSharedRecordsByStatusResponse
                                          .getAllSharedRecordsByStatusList
                                          .map<Widget>((result) {
                                    return Padding(
                                        padding: EdgeInsets.all(10),
                                        child: Row(
                                          children: <Widget>[
                                            Expanded(
                                                flex: 3,
                                                child: AppText(
                                                    result.patientName)),
                                            Expanded(
                                                flex: 1,
                                                child: IconButton(
                                                  icon: Icon(
                                                    Icons.delete,
                                                    color: Colors.black,
                                                  ),
                                                  onPressed: () {
                                                    deactivateRequest(
                                                        result.iD, 5, context);
                                                  },
                                                )),
                                          ],
                                        ));
                                  }).toList())
                                ])
                              ],
                            );
                      }
                    })
              ],
            ))
          ],
        ),
      ),
    );
  }

  String isAvailable() {
    if (isVaiable == false) {
      this.isVaiable = true;
      return TranslationBase.of(context).noDataAvailable;
    } else {
      return "";
    }
  }

  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();
      }
    }
  }

  Future getUserViewRequest() async {
    var user = await sharedPref.getObject(USER_PROFILE);
    return familyFileProvider.getUserViewRequest(user['PatientID']);
  }

  Future<GetAllSharedRecordsByStatusResponse> getSentRequest() async {
    // var user = await sharedPref.getObject(USER_PROFILE);
    return familyFileProvider.getUserSentRequest();
  }

  deleteFamily(family, context) {
    ConfirmDialog dialog = new ConfirmDialog(
        context: context,
        confirmMessage: TranslationBase.of(context).removeFamilyMember,
        okText: TranslationBase.of(context).confirm,
        cancelText: TranslationBase.of(context).cancel_nocaps,
        okFunction: () => {
              ConfirmDialog.closeAlertDialog(context),
              removeFamily(family, context)
            },
        cancelFunction: () => {});
    dialog.showAlertDialog(context);
  }

  removeFamily(GetAllSharedRecordsByStatusList family, context) {
    GifLoaderDialogUtils.showMyDialog(context);
    this.userID = family.iD;
    Map<String, dynamic> request = {};
    request['ID'] = this.userID;
    request['IsActive'] = false;
    this
        .familyFileProvider
        .deativateActivateMemberFile(request)
        .then((value) => refreshFamily(context));
  }

  refreshFamily(context) {
    GifLoaderDialogUtils.hideDialog(context);
    setState(() {
      sharedPref.remove(FAMILY_FILE);
    });
  }

  switchUser(user, context) {
    GifLoaderDialogUtils.showMyDialog(context);
    // this
    //     .familyFileProvider
    //     .silentLoggin(user)
    //     .then((value) => loginAfter(value, context));

    // Utils.showProgressDialog(context);
    this
        .familyFileProvider
        .silentLoggin(user is AuthenticatedUser ? null : user,
            mainUser: user is AuthenticatedUser)
        .then((value) => loginAfter(value, context))
        .catchError((err) {
      print(err);
      AppToast.showErrorToast(message: err);
      Navigator.of(context).pop();
    });
  }

  loginAfter(result, context) async {
    GifLoaderDialogUtils.hideDialog(context);
    var currentLang = await sharedPref.getString(APP_LANGUAGE);
    Provider.of<ProjectViewModel>(context, listen: false)
        .setPrivilege(privilegeList: result, isLoginChild: true);
    result = list.CheckActivationCode.fromJson(result);
    var familyFile = await sharedPref.getObject(FAMILY_FILE);

    result = list.CheckActivationCode.fromJson(result);
    var mainUser = await sharedPref.getObject(MAIN_USER);
    var bloodType = await sharedPref.getString(BLOOD_TYPE);
    this.sharedPref.clear();
    if (mainUser["PatientID"] != result.list.patientID) {
      result.list.isFamily = true;
    }
    this.sharedPref.setString(APP_LANGUAGE, currentLang);
    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);
    await authenticatedUserObject.getUser(getUser: true);
    Provider.of<ProjectViewModel>(context, listen: false).user =
        authenticatedUserObject.user;
    Provider.of<ProjectViewModel>(context, listen: false)
        .setUser(authenticatedUserObject.user);

    await pharmacyModuleViewModel.generatePharmacyToken().then((value) async {
      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);
    });
  }

  deactivateRequest(ID, status, context) {
    GifLoaderDialogUtils.showMyDialog(context);
    Map<String, dynamic> request = {};
    request["ID"] = ID;
    request["Status"] = status;
    this.familyFileProvider.deactivateFamily(request).then((value) =>
        {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)});
  }

  acceptRemoveRequest(ID, status, context) {
    GifLoaderDialogUtils.showMyDialog(context);
    Map<String, dynamic> request = {};
    request["ID"] = ID;
    request["Status"] = status;
    this.familyFileProvider.acceptRejectFamily(request).then((value) =>
        {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)});
  }

  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));
      print(data2);
      setState(() {
        this.user = data;
      });
    }
  }
}
