114 lines
4.1 KiB
Dart
114 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:citycards_customer/common_packages/custom_text.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
class CustomTextField extends StatelessWidget {
|
|
final String label;
|
|
final String hint;
|
|
final TextEditingController controller;
|
|
final int? maxLines;
|
|
final bool enabled;
|
|
final String? Function(String?)? validator; // ✅ NEW: Validator function
|
|
final TextInputType? keyboardType; // ✅ NEW: Keyboard type
|
|
final bool obscureText; // ✅ NEW: For password fields
|
|
final Widget? suffixIcon; // ✅ NEW: For icons like visibility toggle
|
|
final void Function(String)? onChanged; // ✅ NEW: OnChanged callback
|
|
|
|
const CustomTextField({
|
|
super.key,
|
|
required this.label,
|
|
required this.hint,
|
|
required this.controller,
|
|
this.maxLines = 1,
|
|
this.enabled = true,
|
|
this.validator,
|
|
this.keyboardType,
|
|
this.obscureText = false,
|
|
this.suffixIcon,
|
|
this.onChanged,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: EdgeInsets.only(bottom: 12.h),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CustomText(
|
|
text: label,
|
|
size: 14.sp,
|
|
),
|
|
SizedBox(height: 6.h),
|
|
SizedBox(
|
|
height: maxLines == 1 ? 42.h : null,
|
|
child: TextFormField( // ✅ Changed from TextField to TextFormField
|
|
controller: controller,
|
|
maxLines: obscureText ? 1 : maxLines, // ✅ Password fields always single line
|
|
enabled: enabled,
|
|
validator: validator, // ✅ Added validator
|
|
keyboardType: keyboardType, // ✅ Added keyboard type
|
|
obscureText: obscureText, // ✅ Added obscure text
|
|
onChanged: onChanged, // ✅ Added onChanged
|
|
decoration: InputDecoration(
|
|
hintText: hint,
|
|
hintStyle: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: const Color(0xFF8E8E8E),
|
|
),
|
|
filled: true,
|
|
fillColor: enabled
|
|
? const Color(0xFFFFF5F5)
|
|
: Colors.grey.shade200,
|
|
contentPadding: EdgeInsets.symmetric(
|
|
horizontal: 24.w,
|
|
vertical: maxLines != null && maxLines! > 1 ? 12.h : 0, // ✅ Better padding for multiline
|
|
),
|
|
suffixIcon: suffixIcon, // ✅ Added suffix icon
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(
|
|
color: const Color(0xBBC83B61).withOpacity(0.4),
|
|
width: .4.w,
|
|
),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(
|
|
color: const Color(0xFFF95F62),
|
|
width: 1.w,
|
|
),
|
|
),
|
|
disabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(
|
|
color: Colors.grey.shade400,
|
|
width: .4.w,
|
|
),
|
|
),
|
|
errorBorder: OutlineInputBorder( // ✅ NEW: Error state border
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(
|
|
color: Colors.red,
|
|
width: 1.w,
|
|
),
|
|
),
|
|
focusedErrorBorder: OutlineInputBorder( // ✅ NEW: Focused error state
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(
|
|
color: Colors.red,
|
|
width: 1.5.w,
|
|
),
|
|
),
|
|
errorStyle: TextStyle( // ✅ NEW: Error text style
|
|
fontSize: 11.sp,
|
|
color: Colors.red,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |