| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import 'package:flutter/material.dart';
- import 'package:water_management_system/utils/constants.dart';
-
- class CustomTextField extends StatelessWidget {
- final TextEditingController controller;
- final String labelText;
- final String? hintText;
- final IconData? prefixIcon;
- final Widget? suffixIcon;
- final bool obscureText;
- final String? Function(String?)? validator;
- final void(String)? onChanged;
- final void(String)? onSubmitted;
- final TextInputType? keyboardType;
- final int? maxLength;
- final int? maxLines;
- final bool enabled;
- final FocusNode? focusNode;
-
- const CustomTextField({
- super.key,
- required this.controller,
- required this.labelText,
- this.hintText,
- this.prefixIcon,
- this.suffixIcon,
- this.obscureText = false,
- this.validator,
- this.onChanged,
- this.onSubmitted,
- this.keyboardType,
- this.maxLength,
- this.maxLines = 1,
- this.enabled = true,
- this.focusNode,
- });
-
- @override
- Widget build(BuildContext context) {
- return TextFormField(
- controller: controller,
- decoration: InputDecoration(
- labelText: labelText,
- hintText: hintText,
- prefixIcon: prefixIcon != null
- ? Icon(
- prefixIcon,
- color: Colors.grey[600],
- )
- : null,
- suffixIcon: suffixIcon,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- ),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- borderSide: BorderSide(
- color: Colors.grey[300]!,
- ),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- borderSide: const BorderSide(
- color: AppConstants.primaryColor,
- width: 2,
- ),
- ),
- errorBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- borderSide: const BorderSide(
- color: AppConstants.errorColor,
- width: 1,
- ),
- ),
- focusedErrorBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- borderSide: const BorderSide(
- color: AppConstants.errorColor,
- width: 2,
- ),
- ),
- filled: true,
- fillColor: enabled ? Colors.white : Colors.grey[100],
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 12,
- ),
- ),
- obscureText: obscureText,
- validator: validator,
- onChanged: onChanged,
- onFieldSubmitted: onSubmitted,
- keyboardType: keyboardType,
- maxLength: maxLength,
- maxLines: maxLines,
- enabled: enabled,
- focusNode: focusNode,
- style: TextStyle(
- color: enabled ? Colors.black87 : Colors.grey[500],
- ),
- );
- }
- }
|