import 'package:anchor_collect_flutter/routes/routes.dart';
import 'package:anchor_collect_flutter/utils/dialog_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../congifs.dart';
import '../../utils/sp_helper.dart';
import 'mine_logic.dart';

class MinePage extends StatelessWidget {
  MinePage({Key? key}) : super(key: key);

  final logic = Get.find<MineLogic>();
  final state = Get
      .find<MineLogic>()
      .state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('我的'),
        centerTitle: true,
        backgroundColor: Colors.blue,
      ),
      body: Stack(
        children: [

          ///下层背景
          Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              Container(
                width: double.infinity,
                height: 200,
                color: Colors.blue,
              ),
              Expanded(
                child: Container(
                  width: double.infinity,
                  color: const Color(0xf5f6f8),
                ),
              ),
            ],
          ),

          ///上层
          GetBuilder<MineLogic>(builder: (logic) {
            return Column(
              mainAxisSize: MainAxisSize.max,
              children: [
                Padding(
                  padding: const EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 20.0),
                  child: Row(
                    children: [
                      CircleAvatar(
                        radius: 35, // 头像的半径大小
                        backgroundImage: AssetImage('images/ic_launcher.png'), // 头像的图片路径
                        child: Container(
                          // 边框容器
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            border: Border.all(
                              color: Colors.grey, // 边框的颜色
                              width: 2, // 边框的宽度
                            ),
                          ),
                        ),
                      ),
                      SizedBox(
                        width: 10,
                      ),
                      Text(
                        state.deptName,
                        style: TextStyle(
                          fontSize: 20,
                          color: Colors.white,
                        ),
                      ),
                      Expanded(child: SizedBox()),
                      Text(
                        '个人信息>',
                        style: TextStyle(
                          fontSize: 16,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Column(
                      children: [
                        ListTile(
                          title: const Text('编辑资料'),
                          leading: const Icon(Icons.account_box),
                          trailing: const Icon(Icons.add),
                          onTap: () => {},
                        ),
                        SizedBox(
                          height: 1,
                          child: Container(
                            height: 1,
                            color: Colors.black12,
                          ),
                        ),
                        ListTile(
                          title: const Text('关于我们'),
                          leading: const Icon(Icons.accessibility),
                          trailing: const Icon(Icons.add),
                          onTap: () => {},
                        ),
                        SizedBox(
                          height: 1,
                          child: Container(
                            height: 1,
                            color: Colors.black12,
                          ),
                        ),
                        ListTile(
                          title: const Text('修改密码'),
                          leading: const Icon(Icons.account_balance_wallet_outlined),
                          trailing: const Icon(Icons.add),
                          onTap: () => {},
                        ),
                        SizedBox(
                          height: 1,
                          child: Container(
                            height: 1,
                            color: Colors.black12,
                          ),
                        ),
                        ListTile(
                          title: const Text('检查更新'),
                          leading: const Icon(Icons.ad_units_outlined),
                          trailing: const Icon(Icons.add),
                          onTap: () =>
                          {
                            if(Config.isOnLine){
                              logic.checkUpdate(),
                            }
                          },
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(
                  height: 30,
                ),
                Row(children: [
                  const SizedBox(
                    width: 10,
                  ),
                  Expanded(
                    child: TextButton(
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(Colors.blue),
                        foregroundColor: MaterialStateProperty.all(Colors.white),
                        padding: MaterialStateProperty.all(const EdgeInsets.all(8)),
                      ),
                      onPressed: () =>
                      {
                      logic.logout(),
                      },
                      child: const Text("退出登录"),
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                ]),
              ],
            );
          }),
        ],
      ),
    );
  }
}
