import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; class CustomAppTextField extends StatelessWidget { final TextEditingController controller; final String label; final String? hintText; final TextInputType? keyboardType; final bool obscureText; final bool enabled; final bool readOnly; final VoidCallback? onTap; final IconData? suffixIcon; final bool isRequired; final String? Function(String?)? validator; // Permettre un validateur personnalisé const CustomAppTextField({ super.key, required this.controller, required this.label, this.hintText, this.keyboardType, this.obscureText = false, this.enabled = true, this.readOnly = false, this.onTap, this.suffixIcon, this.isRequired = true, this.validator, }); @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( label, style: GoogleFonts.merienda(fontSize: 14, fontWeight: FontWeight.w600, color: Colors.black87), ), const SizedBox(height: 4), Container( height: 45, decoration: const BoxDecoration( image: DecorationImage( image: AssetImage('assets/images/input_field_bg.png'), fit: BoxFit.fill, ), ), child: TextFormField( controller: controller, keyboardType: keyboardType, obscureText: obscureText, enabled: enabled, readOnly: readOnly, onTap: onTap, style: GoogleFonts.merienda(fontSize: 15, color: enabled ? Colors.black87 : Colors.grey), textAlignVertical: TextAlignVertical.center, decoration: InputDecoration( border: InputBorder.none, contentPadding: const EdgeInsets.fromLTRB(15, 13, 15, 11), hintText: hintText, hintStyle: GoogleFonts.merienda(fontSize: 15, color: Colors.black38), suffixIcon: suffixIcon != null ? Padding( padding: const EdgeInsets.only(right: 8.0), child: Icon(suffixIcon, color: Colors.black54, size: 20), ) : null, isDense: true, ), validator: validator ?? // Utilise le validateur fourni, ou celui par défaut (value) { if (!enabled) return null; if (readOnly) return null; if (isRequired && (value == null || value.isEmpty)) { return 'Ce champ est obligatoire'; } return null; }, ), ), ], ); } }