import 'package:capture/capture/cpature_images.dart';
import 'package:capture/common/settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:dots_indicator/dots_indicator.dart';


class Dashboard extends StatefulWidget {
  const Dashboard({Key? key}) : super(key: key);

  @override
  State<Dashboard> createState() => _DashboardState();
}

class _DashboardState extends State<Dashboard> {
  final List<String> imgList = [
    'images/mobilebg.png',
    'images/mobilebg2.png',
    'images/mobilebg3.png'
  ];

  bool isTablet = false;
  bool isPhone = true;
  int currentIndex = 0;

  Widget _newDashboard() {
    return Container(
        color: secondaryColor,
        child: Column(children: <Widget>[
         /* CarouselSlider(
            options: CarouselOptions(
              height: MediaQuery.of(context).size.height * .250,
              aspectRatio: 16 / 9,
              viewportFraction: 0.8,
              initialPage: 0,
              enableInfiniteScroll: true,
              reverse: false,
              autoPlay: true,
              autoPlayInterval: Duration(seconds: 3),
              autoPlayAnimationDuration: Duration(milliseconds: 800),
              autoPlayCurve: Curves.ease,
              enlargeCenterPage: true,
              onPageChanged: (index, reason) {
                setState(() {
                  currentIndex = index;
                });
              },
              enlargeFactor: 0.2,
              scrollDirection: Axis.horizontal,
            ),
            items: imgList.map((i) {
              return Builder(
                builder: (BuildContext context) {
                  return Container(
                      height: MediaQuery.of(context).size.height * .250,
                      width: double.infinity,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(0),
                      ),
                      //color: Colors.red,
                      child: FittedBox(
                        child: Image(
                          image: AssetImage(i),
                        ),
                        fit: BoxFit.fill,
                      ));
                },
              );
            }).toList(),
          ),
          DotsIndicator(
              dotsCount: imgList.length,
              position: currentIndex,
              axis: Axis.horizontal,
              decorator: DotsDecorator(
                  color: Colors.white,
                  activeColor: buttonColors
              )
            //decorator: decorator,
          ),*/
          Padding(
            padding: EdgeInsets.all(10),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Column(
                  children: [
                    GestureDetector(
                      child: Container(
                        width: MediaQuery.of(context).size.width * .20,
                        height: MediaQuery.of(context).size.height * .15,
                        decoration: BoxDecoration(
                            color: Colors.white,
                            shape: BoxShape.circle,
                            image: DecorationImage(
                                image: AssetImage(
                                    "images/seekopinion.png"), // picked file
                                fit: BoxFit.fitWidth)),
                      ),
                      onTap: () {
                         Navigator.push(
                           context,
                           MaterialPageRoute(
                              builder: (context) => const MedicineCapture()),
                         );
                      },
                    ),
                    Text(
                      'Capture Medicines',
                      style: dashboardTextStyle(),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ]));
  }


  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        final shouldPop = await showDialog<bool>(
          context: context,
          builder: (context) {
            return AlertDialog(
              title: const Text('Do you want to exit app?',
                  style: TextStyle(
                    color: primaryColor,
                    fontSize: 20,
                  )),
              actionsAlignment: MainAxisAlignment.spaceBetween,
              actions: [
                TextButton(
                  onPressed: () {
                    SystemNavigator.pop();
                  },
                  child: const Text('Yes',
                      style: TextStyle(
                        color: primaryColor,
                        fontSize: 20,
                      )),
                ),
                TextButton(
                  onPressed: () {
                    Navigator.of(context).pop(false);
                  },
                  child: const Text('No',
                      style: TextStyle(
                        color: primaryColor,
                        fontSize: 20,
                      )),
                ),
              ],
            );
          },
        );
        return shouldPop!;
      },
      child: Scaffold(
        backgroundColor: primaryColor,
        resizeToAvoidBottomInset: false,
        appBar: AppSettings.appBar('Health Care'),
        drawer: Drawer(
          backgroundColor: primaryColor,
          child: ListView(
            padding: EdgeInsets.zero,
            children: [
              DrawerHeader(
                decoration: const BoxDecoration(
                  color: buttonColors,
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        GestureDetector(
                          child: Container(
                            width: MediaQuery.of(context).size.width * .20,
                            height:
                            MediaQuery.of(context).size.height * .15,
                            decoration: BoxDecoration(

                              shape: BoxShape.circle,
                              image: DecorationImage(
                                  image: (AppSettings.profilePictureUrl !=
                                      '' &&
                                      AppSettings.profilePictureUrl !=
                                          'null')
                                      ? NetworkImage(AppSettings
                                      .profilePictureUrl)
                                  as ImageProvider
                                      : AssetImage(
                                      "images/profile_pic.png"),

                                  fit:BoxFit.fitWidth // picked file
                              ),
                            ),
                          ),
                          onTap: () {
                          },
                        ),
                      ],
                    ),),
                    Text(
                      AppSettings.userName,
                      style: drawerHeaderTextStyleNew(),
                    ),
                    Text(
                      AppSettings.phoneNumber,
                      style: drawerHeaderTextStyleNew(),
                    ),
                    Visibility(
                      visible: AppSettings.email != '',
                      child: Text(
                        AppSettings.email,
                        style: drawerHeaderTextStyleNew(),
                      ),
                    ),
                    Row(
                      children: [
                        Visibility(
                          visible: AppSettings.age != '',
                          child: Text(
                            AppSettings.age + '  Yrs, ',
                            style: drawerHeaderTextStyleNew(),
                          ),
                        ),
                        Visibility(
                          visible: AppSettings.gender != '',
                          child: Text(
                            AppSettings.gender,
                            style: drawerHeaderTextStyleNew(),
                          ),
                        ),
                      ],
                    )
                  ],
                ),),
              ListTile(
                title: Row(
                  children: [
                    Image(
                        image: const AssetImage('images/editprofile.png'),
                        height: 25,
                        width: 25,
                        fit: BoxFit.fill),
                    const SizedBox(
                      width: 10,
                    ),
                    const SizedBox(
                      width: 10,
                    ),
                    Text('Edit Profile', style: drawerListItemsTextStyle()),
                  ],
                ),
                onTap: () {
                 /* Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => const UpdateProfile()),
                  );*/
                },
              ),
              Divider(
                color: Colors.grey,
              ),
              ListTile(
                title: Row(
                  children: [
                    Image(
                        image: const AssetImage('images/logout.png'),
                        height: 25,
                        width: 25,
                        fit: BoxFit.fill),
                    const SizedBox(
                      width: 10,
                    ),
                    const SizedBox(
                      width: 10,
                    ),
                    Text('Logout', style: drawerListItemsTextStyle()),
                  ],
                ),
                onTap: () {
                 // showLogoutAlertDialog(context);
                },
              ),
            ],
          ),
        ),
        body: _newDashboard(),
      ),
    );
  }
}
