72 lines
2.1 KiB
Dart
72 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../utils/app_colors.dart';
|
|
|
|
class CustomTextField extends StatefulWidget {
|
|
final String hintText;
|
|
final String? labelText;
|
|
final IconData? prefixIcon;
|
|
final bool obscureText;
|
|
final TextEditingController? controller;
|
|
final String? Function(String?)? validator;
|
|
final TextInputType? keyboardType;
|
|
final bool enabled;
|
|
final VoidCallback? onSuffixIconPressed;
|
|
|
|
const CustomTextField({
|
|
Key? key,
|
|
required this.hintText,
|
|
this.labelText,
|
|
this.prefixIcon,
|
|
this.obscureText = false,
|
|
this.controller,
|
|
this.validator,
|
|
this.keyboardType,
|
|
this.enabled = true,
|
|
this.onSuffixIconPressed,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<CustomTextField> createState() => _CustomTextFieldState();
|
|
}
|
|
|
|
class _CustomTextFieldState extends State<CustomTextField> {
|
|
bool _isObscured = true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
child: TextFormField(
|
|
controller: widget.controller,
|
|
obscureText: widget.obscureText ? _isObscured : false,
|
|
validator: widget.validator,
|
|
keyboardType: widget.keyboardType,
|
|
enabled: widget.enabled,
|
|
style: const TextStyle(fontSize: 16, color: AppColors.textPrimary),
|
|
decoration: InputDecoration(
|
|
hintText: widget.hintText,
|
|
labelText: widget.labelText,
|
|
prefixIcon:
|
|
widget.prefixIcon != null
|
|
? Icon(widget.prefixIcon, color: AppColors.primaryRed)
|
|
: null,
|
|
suffixIcon:
|
|
widget.obscureText
|
|
? IconButton(
|
|
icon: Icon(
|
|
_isObscured ? Icons.visibility_off : Icons.visibility,
|
|
color: AppColors.secondaryGray,
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
_isObscured = !_isObscured;
|
|
});
|
|
},
|
|
)
|
|
: null,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|