import 'dart:io';

import 'package:carousel_slider/carousel_slider.dart';
import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/pages/medical/smart_watch_health_data/health_data_list.dart';
import 'package:diplomaticquarterapp/services/smartwatch_integration/SmartWatchIntegrationService.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class SmartWatchInstructions extends StatefulWidget {
  @override
  _SmartWatchInstructionsState createState() => _SmartWatchInstructionsState();
}

class _SmartWatchInstructionsState extends State<SmartWatchInstructions> {
  CarouselController buttonCarouselController = CarouselController();

  bool hasAlreadySynced = false;

  AuthenticatedUserObject authenticatedUserObject =
  locator<AuthenticatedUserObject>();

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      if(authenticatedUserObject.isLogin) getLastPatientRecord(context);
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
        appBarTitle: "Sync Health Data",
        isShowAppBar: true,
        isShowDecPage: true,
        description: TranslationBase.of(context).infoHealthData,
        imagesInfo: [
          ImagesInfo(imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/health-data/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/health-data/ar/0.png'),
          ImagesInfo(imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/health-data/en/1.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/health-data/ar/1.png')
        ],
        body: Container(
          child: Platform.isIOS
              ? _getAppleWatchInstructions()
              : _getGoogleWatchInstructions(),
        ));
  }

  _getAppleWatchInstructions() {
    return SingleChildScrollView(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(top: 10.0),
            child: CarouselSlider(
              carouselController: buttonCarouselController,
              options: CarouselOptions(
                  enableInfiniteScroll: false,
                  viewportFraction: 0.95,
                  height: MediaQuery.of(context).size.height * 0.9),
              items: [1, 2].map((i) {
                return Builder(
                  builder: (BuildContext context) {
                    return Container(
                        width: MediaQuery.of(context).size.width,
                        margin: EdgeInsets.symmetric(horizontal: 5.0),
                        child: Card(
                          margin: EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 8.0),
                          color: Colors.white.withOpacity(1.0),
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: i == 1
                              ? Column(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Text("Supported Smartwatches",
                                          style: TextStyle(
                                              fontSize: 22.0,
                                              fontWeight: FontWeight.bold,
                                              fontFamily: "WorkSans")),
                                    ),
                                    Container(
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 10.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/apple-watch-1.jpeg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 1", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 10.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/apple-watch-2.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 2", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/apple-watch-3.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 3", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/apple-watch-4.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 4", overflow: TextOverflow.clip ,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/apple-watch-5.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 5", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/Apple-Watch-6.png",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Apple Watch Series 6", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/miBand3.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Mi Band 3", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/miBand4.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Mi Band 4", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.fromLTRB(
                                          10.0, 30.0, 10.0, 10.0),
                                      child: Text(
                                          "It Seems like you haven't synced your health data with the Dr. Alhabib App before. To proceed further, you need to sync your health data with the Dr. Alhabib App",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "Before syncing data, please make sure that you have followed the instructions properly",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            buttonCarouselController.nextPage();
                                          },
                                          child: Text("CONTINUE",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ),
                                  ],
                                )
                              : Column(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Text("Watch Instructions:",
                                          style: TextStyle(
                                              fontSize: 22.0,
                                              fontWeight: FontWeight.bold,
                                              fontFamily: "WorkSans")),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "It Seems like you haven't synced your health data with the Dr. Alhabib App before. To proceed further, you need to sync your health data with the Dr. Alhabib App",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.fromLTRB(
                                          10.0, 20.0, 10.0, 10.0),
                                      child: Text(
                                          "Before syncing data, please make sure that following instructions are met: ",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.fromLTRB(
                                          10.0, 20.0, 10.0, 10.0),
                                      child: Text(
                                          "1. Make sure that you have installed 'Health' App & 'Watch' App from Apple Store.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "2. Make sure that your Apple Watch is connected with the Watch & Health Apps.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "3. Make sure that data like heart rate, steps, distance etc. are being shown on your health app.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.fromLTRB(
                                          15.0, 110.0, 15.0, 15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            buttonCarouselController.nextPage();
                                          },
                                          child: Text("SYNC HEALTH DATA",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ),
                                    hasAlreadySynced ? Container(
                                      margin: EdgeInsets.fromLTRB(
                                          15.0, 0.0, 15.0, 15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            _openHealthDataList();
                                          },
                                          child: Text("ALREADY SYNCED",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ): Container(),
                                  ],
                                ),
                        ));
                  },
                );
              }).toList(),
            ),
          )
        ],
      ),
    );
  }

  _getGoogleWatchInstructions() {
    return SingleChildScrollView(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(top: 10.0),
            child: CarouselSlider(
              carouselController: buttonCarouselController,
              options: CarouselOptions(
                  // enableInfiniteScroll: true,
                  viewportFraction: 0.99,
                  height: MediaQuery.of(context).size.height*1.02 ),
              items: [1, 2].map((i) {
                return Builder(
                  builder: (BuildContext context) {
                    return Container(
                        width: MediaQuery.of(context).size.width,
                        margin: EdgeInsets.symmetric(horizontal: 5.0),
                        child: Card(
                          margin: EdgeInsets.only(top:16.0 , bottom: 8.0),
                          // fromLTRB(8.0, 16.0, 8.0, 8.0),
                          color: Colors.white.withOpacity(1.0),
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: i == 1
                              ? Column(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Text("Supported Smartwatches",
                                          style: TextStyle(
                                              fontSize: 22.0,
                                              fontWeight: FontWeight.bold,
                                              fontFamily: "WorkSans")),
                                    ),
                                    Container(
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 10.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/huawei-watch-2.png",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Huawei Watch 2", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 10.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/ticwatche2.png",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "Mobovi TicWatch E2",
                                                        overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/huawei-watch-2-classic.png",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Huawei Watch", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/ticwatche2.png",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Fossil Sport", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/misfit-vapor-2.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "MisFit Vapor 2", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/lg-watch-sport.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text(
                                                        "LG Watch Sport", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/miBand3.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Mi Band 3", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin:
                                                  EdgeInsets.only(top: 15.0),
                                              child: Row(
                                                children: [
                                                  Image.asset(
                                                      "assets/images/SmartWatches/miBand4.jpg",
                                                      width: 70.0,
                                                      height: 70.0),
                                                  Container(
                                                    width: MediaQuery.of(context).size.width*0.22,
                                                    child: Text("Mi Band 4", overflow: TextOverflow.clip,
                                                        style: TextStyle(
                                                            fontSize: 12.0)),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    InkWell(
                                      onTap: () {
                                        launch(
                                            "https://wearos.google.com/#find-your-watch");
                                      },
                                      child: Container(
                                        margin: EdgeInsets.only(top: 20.0),
                                        child: Text(
                                            "More Supported Smartwatches...",
                                            style: TextStyle(
                                                fontSize: 17.0,
                                                color: Colors.blue,
                                                decoration:
                                                    TextDecoration.underline)),
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "It Seems like you haven't synced your health data with the Dr. Alhabib App before. To proceed further, you need to sync your health data with the Dr. Alhabib App",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "Before syncing data, please make sure that you have followed the instructions properly",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            buttonCarouselController.nextPage();
                                          },
                                          child: Text("CONTINUE",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ),
                                  ],
                                )
                              : Column(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.only(top: 10.0),
                                      child: Text("Watch Instructions:",
                                          style: TextStyle(
                                              fontSize: 22.0,
                                              fontWeight: FontWeight.bold,
                                              fontFamily: "WorkSans")),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "It Seems like you haven't synced your health data with the Dr. Alhabib App before. To proceed further, you need to sync your health data with the Dr. Alhabib App",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "Before syncing data, please make sure that following instructions are met: ",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "1. Make sure that you have installed 'WearOS' & 'Google Fit' apps from Google PlayStore.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "2. Make sure that you have installed your watch related apps from Google PlayStore.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "3. Make sure that your Smart Watch is connected with the WearOS app & your watch apps.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      child: Text(
                                          "4. Make sure that your smart watch apps are linked/associated with Google Fit App.",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(fontSize: 17.0)),
                                    ),
                                    Container(
                                      margin: EdgeInsets.fromLTRB(
                                          15.0, 75.0, 15.0, 15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            buttonCarouselController.nextPage();
                                          },
                                          child: Text("SYNC HEALTH DATA",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ),
                                    hasAlreadySynced ? Container(
                                      margin: EdgeInsets.fromLTRB(
                                          15.0, 0.0, 15.0, 15.0),
                                      child: ButtonTheme(
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(10.0),
                                        ),
                                        minWidth:
                                            MediaQuery.of(context).size.width,
                                        height: 45.0,
                                        child: RaisedButton(
                                          color: new Color(0xFF60686b),
                                          textColor: Colors.white,
                                          disabledTextColor: Colors.white,
                                          disabledColor: new Color(0xFFbcc2c4),
                                          onPressed: () {
                                            _openHealthDataList();
                                          },
                                          child: Text("ALREADY SYNCED",
                                              style: TextStyle(fontSize: 18.0)),
                                        ),
                                      ),
                                    ) : Container(),
                                  ],
                                ),
                        ));
                  },
                );
              }).toList(),
            ),
          )
        ],
      ),
    );
  }

  getLastPatientRecord(BuildContext context) {
    SmartWatchIntegrationService service = new SmartWatchIntegrationService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.getLastPatientRecord(context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      if (res['MessageStatus'] == 1) {
        print(res['Med_GetPatientLastRecordList']);
        setState(() {
          if (res['Med_GetPatientLastRecordList'] != null)
            hasAlreadySynced = true;
          else
            hasAlreadySynced = false;
        });
      } else {}
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
    });
  }

  _openHealthDataList() {
    Navigator.push(
        context, MaterialPageRoute(builder: (context) => HealthDataList()));
  }
}
