| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:flutter/material.dart';
-
- class AppTextField extends StatelessWidget {
- final TextEditingController controller;
- final String labelText;
- final String? hintText;
- final TextInputType keyboardType;
- final bool obscureText;
- final bool enabled;
- final int? maxLines;
- final int? maxLength;
- final String? Function(String?)? validator;
- final void Function(String)? onChanged;
- final Widget? suffixIcon;
- final Widget? prefixIcon;
- final bool showCounter;
-
- const AppTextField({
- super.key,
- required this.controller,
- required this.labelText,
- this.hintText,
- this.keyboardType = TextInputType.text,
- this.obscureText = false,
- this.enabled = true,
- this.maxLines = 1,
- this.maxLength,
- this.validator,
- this.onChanged,
- this.suffixIcon,
- this.prefixIcon,
- this.showCounter = false,
- });
-
- @override
- Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- labelText,
- style: const TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.w500,
- color: Colors.black87,
- ),
- ),
- const SizedBox(height: 8),
- TextFormField(
- controller: controller,
- keyboardType: keyboardType,
- obscureText: obscureText,
- enabled: enabled,
- maxLines: maxLines,
- maxLength: maxLength,
- validator: validator,
- onChanged: onChanged,
- decoration: InputDecoration(
- hintText: hintText,
- prefixIcon: prefixIcon,
- suffixIcon: suffixIcon,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10),
- borderSide: const BorderSide(color: Colors.grey),
- ),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10),
- borderSide: const BorderSide(color: Colors.grey),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10),
- borderSide: BorderSide(color: Theme.of(context).primaryColor),
- ),
- errorBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10),
- borderSide: const BorderSide(color: Colors.red),
- ),
- filled: true,
- fillColor: Colors.grey[50],
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 14,
- ),
- counterText: showCounter ? null : '',
- ),
- ),
- ],
- );
- }
- }
|