import 'package:flutter/material.dart'; class MyTextField extends StatefulWidget { final String hintText; final bool obscureText; final TextEditingController controller; final FocusNode? focusNode; const MyTextField({ super.key, required this.hintText, required this.obscureText, required this.controller, this.focusNode, }); @override State createState() => _MyTextFieldState(); } class _MyTextFieldState extends State { late bool _visibleText; @override void initState() { super.initState(); _visibleText = widget.obscureText; } void _toggleObscureText() { setState(() { _visibleText = !_visibleText; }); } @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8), child: TextField( obscureText: _visibleText, controller: widget.controller, focusNode: widget.focusNode, decoration: InputDecoration( enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Theme.of(context).colorScheme.tertiary), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Theme.of(context).colorScheme.primary), ), filled: true, hintText: widget.hintText, suffixIcon: widget.obscureText ? IconButton( icon: Icon( _visibleText ? Icons.visibility : Icons.visibility_off, ), onPressed: _toggleObscureText, ) : null, ), ), ); } }