import 'package:diplomaticquarterapp/pages/medical/smart_watch_health_data/stepsTracker.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
// import 'package:fit_kit/fit_kit.dart';
import 'package:flutter/material.dart';

class HealthDataList extends StatefulWidget {
  @override
  _HealthDataListState createState() => _HealthDataListState();
}

class _HealthDataListState extends State<HealthDataList> {

  // List<DataType> dataTypes = List();

  @override
  void initState() {
    // dataTypes.add(DataType.DISTANCE);
    // dataTypes.add(DataType.STEP_COUNT);
    // dataTypes.add(DataType.HEART_RATE);
    // dataTypes.add(DataType.SLEEP);
    // dataTypes.add(DataType.ENERGY);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
        appBarTitle: "Smartwatches",
        isShowAppBar: true,
        body: Container(
          height: MediaQuery
              .of(context)
              .size
              .height,
          margin: EdgeInsets.all(20.0),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Container(
                      child: Image.asset(
                          "assets/images/SmartWatches/heartrate_icon.png",
                          width: 60.0,
                          height: 60.0),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 0.0),
                      child: Text("Heart Rate",
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold)),
                    ),
                  ],
                ),
                Divider(
                  color: Colors.grey[500],
                ),
                Row(
                  children: [
                    Container(
                      child: Image.asset(
                          "assets/images/SmartWatches/sleep_data.png",
                          width: 60.0,
                          height: 60.0),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 0.0),
                      child: Text("Sleep Data",
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold)),
                    ),
                  ],
                ),
                Divider(
                  color: Colors.grey[500],
                ),
                InkWell(
                  onTap: () {
                    Navigator.push(
                      context,
                      FadePage(
                        page: StepsTracker(),
                      ),
                    );
                  },
                  child: Row(
                    children: [
                      Container(
                        child: Image.asset(
                            "assets/images/SmartWatches/heartrate_icon.png",
                            width: 60.0,
                            height: 60.0),
                      ),
                      Container(
                        margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 0.0),
                        child: Text("Steps",
                            style: TextStyle(
                                fontSize: 20.0, fontWeight: FontWeight.bold)),
                      ),
                    ],
                  ),
                ),
                Divider(
                  color: Colors.grey[500],
                ),
                Row(
                  children: [
                    Container(
                      child: Image.asset(
                          "assets/images/SmartWatches/heartrate_icon.png",
                          width: 60.0,
                          height: 60.0),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 0.0),
                      child: Text("Distance",
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold)),
                    ),
                  ],
                ),
                Divider(
                  color: Colors.grey[500],
                ),
                Row(
                  children: [
                    Container(
                      child: Image.asset(
                          "assets/images/SmartWatches/heartrate_icon.png",
                          width: 60.0,
                          height: 60.0),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 0.0),
                      child: Text("Energy",
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold)),
                    ),
                  ],
                ),
                Divider(
                  color: Colors.grey[500],
                ),
              ],
            ),
          ),
        ),
        bottomSheet: Container(
          width: double.infinity,
          height: MediaQuery
              .of(context)
              .size
              .height * 0.1,
          color: Colors.grey[100],
          child: Column(
            children: <Widget>[
              Divider(
                color: Colors.transparent,
              ),
              InkWell(
                onTap: () {
                  print("ReadLast");
                  // readLast();
                },
                child:Container(
                  height: (MediaQuery
                      .of(context)
                      .size
                      .height/2)*0.12,
                  width: MediaQuery
                      .of(context)
                      .size
                      .width * 0.8,
                  decoration: BoxDecoration(
                    color: Colors.grey[800],
                    borderRadius: BorderRadius.circular(6.0),
                  ),
                  child: Container(
                    padding: EdgeInsets.only(top: 10.0),
                    child: Text(
                        'Sync Health Data' , textAlign: TextAlign.center,style: TextStyle(
                      color: Colors.white , fontSize: 18.0
                    ),
                    ),
                  ),),),
            ],
          ),
        ));
  }


  // void readLast() async {
  //   print("ReadLast");
  //   final result = await FitKit.readLast(DataType.DISTANCE);
  //   print(result);
  //   print(result);
  // }
  //
  // void readAll() async {
  //   if (await FitKit.requestPermissions(dataTypes)) {
  //     for (DataType type in dataTypes) {
  //       final results = await FitKit.read(
  //         type,
  //         dateFrom: DateTime.now().subtract(Duration(days: 7)),
  //         dateTo: DateTime.now(),
  //         limit: 100,
  //       );
  //       print(results);
  //       print(results.length);
  //     }
  //     readLast();
  //   }
  // }
}