import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:manager_app/Components/text_field_container.dart'; import 'package:manager_app/constants.dart'; class RoundedInputField extends StatelessWidget { final String? hintText; final IconData? icon; final ValueChanged onChanged; final String? initialValue; final Color color, textColor, iconColor; final int? maxLength; final bool isEmail; final double fontSize; final String? autofill; final bool isInt; /// A preferer a [initialValue] pour un champ vivant dans un ecran qui se /// reconstruit : le texte survit alors a la reconstruction du TextFormField. final TextEditingController? controller; const RoundedInputField({ Key? key, this.hintText, this.initialValue, this.icon, this.color = kSurface2, this.textColor = kInk, this.iconColor = kPrimaryColor, required this.onChanged, this.maxLength, // 50 this.isEmail = false, this.fontSize = 13, this.autofill, this.isInt = false, this.controller, }) : super(key: key); @override Widget build(BuildContext context) { return TextFieldContainer( color: color, child: TextFormField ( onChanged: onChanged, controller: controller, initialValue: controller == null ? initialValue : null, cursorColor: textColor, maxLength: maxLength, autofillHints: autofill != null ? [autofill!] : const [], keyboardType: isEmail ? TextInputType.emailAddress : isInt ? TextInputType.number : TextInputType.text, inputFormatters: !isInt ? [] : [ FilteringTextInputFormatter.digitsOnly ], style: TextStyle(fontSize: fontSize, color: textColor), // Le compteur reste, mais discret : c'est une indication, pas une ligne de texte. buildCounter: maxLength == null ? null : (context, {required currentLength, required isFocused, maxLength}) => Text('$currentLength/$maxLength', style: const TextStyle(fontSize: 10.5, color: kInk3)), decoration: InputDecoration( isDense: true, contentPadding: const EdgeInsets.symmetric(vertical: kSpace3), icon: icon != null ? Icon( icon, color: iconColor, ): null, hintText: hintText, hintStyle: TextStyle(fontSize: fontSize, color: kInk3, fontWeight: FontWeight.w400), border: InputBorder.none, ) ), ); } }