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


class PasswordField extends StatefulWidget {
  final TextEditingController controller;

  const PasswordField({
    super.key,
    required this.controller,
  });

  @override
  State<PasswordField> createState() => _PasswordFieldState();
}

class _PasswordFieldState extends State<PasswordField> {
  bool _obscureText = true;

  void _toggleVisibility() {
    setState(() {
      _obscureText = !_obscureText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      controller: widget.controller,
      obscureText: _obscureText,
      style: TextStyle(color: Color(0xFF333333), fontSize: 28.sp),
      validator: (val) {
        if (val == null || val.isEmpty) {
          return "密码不能为空";
        }
        return null;
      },
      decoration: InputDecoration(
        filled: true,
        hintText: "password",
        hintStyle: TextStyle(color: Color(0xFF999999), fontSize: 28.sp),
        prefixIcon: Icon(Icons.lock, color: Color(0xFF999999), size: 40.w),
        prefixIconConstraints: BoxConstraints(minWidth: 80.w, minHeight: 80.w),
        suffixIcon: IconButton(
          icon: Icon(
            _obscureText ? Icons.visibility_off : Icons.visibility,
            color: Color(0xFF999999),
            size: 40.w,
          ),
          onPressed: _toggleVisibility,
        ),
        suffixIconConstraints: BoxConstraints(minWidth: 80.w, minHeight: 80.w),
        contentPadding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 24.w),
        helperText: " ",
        helperStyle: TextStyle(height: 1, fontSize: 24.sp),
        errorStyle: TextStyle(color: Colors.red, fontSize: 24.sp, height: 1),
        errorMaxLines: 1,
        fillColor: Colors.white,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(24.w),
          borderSide: BorderSide.none,
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(24.w),
          borderSide: BorderSide(color: Color(0xFFF5F7FA), width: 1),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(24.w),
          borderSide: BorderSide(color: Color(0xFFF5F7FA), width: 1),
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(24.w),
          borderSide: BorderSide(color: Colors.red, width: 1),
        ),
        focusedErrorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(24.w),
          borderSide: BorderSide(color: Colors.red, width: 1.5),
        ),
      ),
    );
  }
}