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

class SetPage extends StatefulWidget {
  const SetPage({super.key});

  @override
  State<SetPage> createState() => _SetPageState();
}

class _SetPageState extends State<SetPage> {
  @override
  Widget build(BuildContext context) {
    final double statusBarHeight = MediaQuery.of(context).padding.top;
    final size = MediaQuery.of(context).size;
    final t10 = size.width / 36;
    final w25 = size.width / 14.4;
    final p5 = size.width / 72;
    final w9 = size.width / 40;
    final s21 = size.width / 17.142857142857;
    final t20 = size.width / 18;

    return Scaffold(
      backgroundColor: const Color(0xFFD8D8D8),
      body: Container(
        decoration: const BoxDecoration(
            image: DecorationImage(
          image: AssetImage('assets/images/home_bg.png'),
          fit: BoxFit.cover,
        )),
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.only(top: statusBarHeight + t10, left: t10, right: t10),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  GestureDetector(
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Container(
                      width: w25,
                      height: w25,
                      padding: EdgeInsets.all(p5),
                      child: Image(
                        width: w9,
                        image: const AssetImage('assets/images/ic_back.png'),
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      '设置',
                      style: TextStyle(fontSize: s21, fontWeight: FontWeight.w600),
                    ),
                  ),
                  Container(
                    width: w25,
                    height: w25,
                    padding: EdgeInsets.all(p5),
                  ),
                ],
              ),
            ),
            GestureDetector(
              onTap: () {
                Navigator.pushNamed(context, "/ChangePasswordPage");
              },
              child: Container(
                height: 50,
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.only(left: 15, right: 15, top: 20),
                padding: EdgeInsets.only(left: 20),
                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8))),
                child: Text(
                  "修改密码",
                  style: TextStyle(
                    fontSize: 16,
                  ),
                ),
              ),
            ),
            GestureDetector(
              onTap: () async {
                final SharedPreferences prefs = await SharedPreferences.getInstance();
                await prefs.setString('token', '');
                Navigator.pushNamedAndRemoveUntil(
                  context,
                  '/LoginPage',
                  (route) => false,
                );
              },
              child: Container(
                height: 50,
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.only(left: 15, right: 15, top: 20),
                padding: EdgeInsets.only(left: 20),
                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8))),
                child: Text(
                  "退出登录",
                  style: TextStyle(fontSize: 16, color: Colors.red),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
