import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../common/Images.dart';

class HomePage extends StatefulWidget {
  @override
  State createState() => _HomePageState();
}

class _HomePageState extends State {
  var currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
        bottomNavigationBar: BottomNavigationBar(
          backgroundColor: Colors.white,
          selectedFontSize: 10,
          unselectedFontSize: 10,
          currentIndex: currentIndex,
          onTap: (index) {
            setState(() {
              currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
                activeIcon: Image.asset(Images.ic_home_selected),
                icon: Image.asset(Images.ic_home_normal),
                label: "处方列表"),
            BottomNavigationBarItem(
                activeIcon: Image.asset(Images.ic_my_selected),
                icon: Image.asset(Images.ic_my_normal),
                label: "我的"),
          ],
        ),
        body: showBody(),
    );
  }

  Widget showBody() {
    if (currentIndex == 0) {
      return home();
    } else {
      return my();
    }
  }

  Widget home() {
    return Container(
      color: Color(0xfff8f8f8),
      child: Column(
        children: [
          Container(
            color: Colors.white,
            alignment: Alignment.center,
            padding: EdgeInsets.only(top: 33, bottom: 9),
            child: Text(
              "处方列表",
              textAlign: TextAlign.center,
              style: TextStyle(color: Color(0xff151515), fontSize: 16),
            ),
          ),
          Container(
            height: 1,
            color: Color(0xfff1f1f1),
          ),
          select(),
          Expanded(
            child: RefreshIndicator(
              onRefresh: handleRefresh,
              child:

              ListView.separated(itemBuilder: (BuildContext context, int index) {
                      return _item();
                    }, separatorBuilder: (BuildContext context, int index) {
                      return Text("data");
                    }, itemCount: 5)

          //     ListView.builder(
          //       padding: EdgeInsets.all(0),
          //       itemCount: 10,
          //       itemBuilder: (BuildContext context, int index) {
          //         return _item();
          //       },
              ),
            ),
          // ),

        ],
      ),
    );
  }

  Widget _item() {
    return Stack(
      children: [
        Container(
          height: 128,
          margin: EdgeInsets.only(left: 16, right: 16, bottom: 16),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(10)),
        ),
        Positioned(right: 10, top: 10, child: Image.asset(Images.ic_state_01)),
        Positioned(
            top: 16,
            left: 32,
            child: Text(
              "R001520041700004",
              style: TextStyle(fontSize: 16, color: Color(0xff151515)),
            )),
        Positioned(
          top: 52,
          left: 34,
          right: 34,
          child: Container(
            height: 1,
            color: Color(0xfff1f1f1),
          ),
        ),
        Positioned(
            top: 64,
            left: 32,
            child: Text(
              "医生姓名：刘泽婷",
              style: TextStyle(fontSize: 16, color: Color(0xff171717)),
            )),
        Positioned(
            top: 92,
            left: 32,
            child: Text(
              "处方时间：2020-04-17 15:3426",
              style: TextStyle(fontSize: 14, color: Color(0xff7D7D7D)),
            ))
      ],
    );
  }

  String text = "下拉刷新 ";

  Future<String> handleRefresh() async {
    text = "刷新中";
    setState(() {});
    await Future.delayed(Duration(milliseconds: 2000));
    text = "刷新完成";
    setState(() {});
    return text;
  }

  var isSelectAll = false;

  Widget select() {
    TextStyle textStyle_01;
    TextStyle textStyle_02;
    BoxDecoration boxDecoration_01;
    BoxDecoration boxDecoration_02;
    // 选中全部
    if (isSelectAll) {
      textStyle_01 =
          TextStyle(color: Colors.white, fontWeight: FontWeight.bold);
      textStyle_02 =
          TextStyle(color: Color(0xff7d7d7d), fontWeight: FontWeight.bold);
      boxDecoration_01 = BoxDecoration(
          borderRadius: BorderRadius.circular(6),
          gradient: LinearGradient(colors: [
            Color(0xff45DAFF),
            Color(0xff3084FF),
          ]));
      boxDecoration_02 = BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6),
      );
    }
    // 选中等待审核
    else {
      textStyle_02 =
          TextStyle(color: Colors.white, fontWeight: FontWeight.bold);
      textStyle_01 =
          TextStyle(color: Color(0xff7d7d7d), fontWeight: FontWeight.bold);
      boxDecoration_02 = BoxDecoration(
          borderRadius: BorderRadius.circular(6),
          gradient: LinearGradient(colors: [
            Color(0xff45DAFF),
            Color(0xff3084FF),
          ]));
      boxDecoration_01 = BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6),
      );
    }

    List<Widget> items = [
      Expanded(
        flex: 1,
        child: Container(
          height: 29,
          margin: EdgeInsets.all(6),
          decoration: boxDecoration_01,
          child: MaterialButton(
            onPressed: () {
              setState(() {
                isSelectAll = true;
              });
            },
            child: Text(
              "等待审核",
              style: textStyle_01,
            ),
          ),
        ),
      ),
      Expanded(
        flex: 1,
        child: Container(
          height: 29,
          margin: EdgeInsets.all(6),
          decoration: boxDecoration_02,
          child: MaterialButton(
            onPressed: () {
              setState(() {
                isSelectAll = false;
              });
            },
            child: Text(
              "全部",
              style: textStyle_02,
            ),
          ),
        ),
      ),
    ];

    return Container(
      child: Container(
        margin: EdgeInsets.all(16),
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(8)),
        child: Row(
          children: items,
        ),
      ),
    );
  }

  Widget my() {
    return Stack(
      children: [
        Positioned(
            top: 0,
            left: 0,
            right: 0,
            child: Image.asset(
              Images.bg_my_01,
              fit: BoxFit.fill,
            )),
        Positioned(
            top: 65,
            left: 39,
            child: Container(
              height: 66,
              width: 66,
              decoration: BoxDecoration(
                  color: Colors.yellow,
                  borderRadius: BorderRadius.circular(33)),
            )),
        Positioned(
            top: 77,
            left: 122,
            child: Text(
              "奈特瑞",
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                  color: Colors.white),
            )),
        Positioned(
            top: 100,
            left: 122,
            child: Text(
              "13570344051",
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                  color: Colors.white),
            )),
        Positioned(
            top: 153,
            left: 16,
            right: 16,
            child: SingleChildScrollView(
                child: Container(
              decoration:
                  BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
              child: Wrap(
                children: [
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_prescription,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("我审核的处方"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_sign,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("电子签名"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_my_info,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("我的信息"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_password,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("密码管理"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_privacy,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("隐私政策"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_on,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("关于"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                  Divider(color: Color(0xfff1f1f1),height: 1,indent: 16,endIndent: 16,),
                  ListTile(
                    title: Row(
                      children: [
                        Image.asset(
                          Images.ic_logout,
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 6),
                          child: Text("退出登录"),
                        ),
                      ],
                    ),
                    trailing: Icon(Icons.chevron_right),
                  ),
                ],
              ),
            )))
      ],
    );
  }
}
