fix textfield width

This commit is contained in:
2025-06-05 16:04:14 +02:00
parent 3d1976d776
commit 7d663f3b96

View File

@@ -84,186 +84,191 @@ class _MihTextFormFieldState extends State<MihTextFormField> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Theme( return SizedBox(
data: Theme.of(context).copyWith( width: widget.width,
textSelectionTheme: TextSelectionThemeData( height: widget.height,
selectionColor: widget.inputColor.withValues(alpha: 0.3), child: Theme(
selectionHandleColor: widget.inputColor, data: Theme.of(context).copyWith(
textSelectionTheme: TextSelectionThemeData(
selectionColor: widget.inputColor.withValues(alpha: 0.3),
selectionHandleColor: widget.inputColor,
),
), ),
), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Row(
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [ Text(
Text( widget.hintText,
widget.hintText, textAlign: TextAlign.left,
textAlign: TextAlign.left,
style: TextStyle(
color: widget.fillColor,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
Visibility(
visible: !widget.requiredText,
child: Text(
"(Optional)",
textAlign: TextAlign.right,
style: TextStyle( style: TextStyle(
color: widget.fillColor, color: widget.fillColor,
fontSize: 15, fontSize: 15,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
), Visibility(
], visible: !widget.requiredText,
), child: Text(
const SizedBox(height: 4), "(Optional)",
FormField<String>( textAlign: TextAlign.right,
initialValue: widget.controller.text, style: TextStyle(
validator: widget.validator, color: widget.fillColor,
autovalidateMode: AutovalidateMode.onUserInteraction, fontSize: 15,
builder: (field) { fontWeight: FontWeight.bold,
_formFieldState = field;
return Column(
crossAxisAlignment:
CrossAxisAlignment.start, // <-- Add this line
children: [
Material(
elevation: widget.elevation ?? 4.0,
borderRadius:
BorderRadius.circular(widget.borderRadius ?? 8.0),
child: SizedBox(
width: widget.width,
height: widget.height,
child: TextFormField(
controller: widget.controller,
cursorColor: widget.inputColor,
autofillHints: widget.autofillHints,
textAlign: TextAlign.start,
textAlignVertical: widget.multiLineInput == true
? TextAlignVertical.top
: TextAlignVertical.center,
obscureText:
widget.passwordMode == true ? _obscureText : false,
expands: widget.passwordMode == true
? false
: (widget.multiLineInput ?? false),
maxLines: widget.passwordMode == true ? 1 : null,
readOnly: widget.readOnly ?? false,
keyboardType: widget.numberMode == true
? TextInputType.number
: null,
inputFormatters: widget.numberMode == true
? [FilteringTextInputFormatter.digitsOnly]
: null,
style: TextStyle(
color: widget.inputColor,
fontWeight: FontWeight.w500,
),
decoration: InputDecoration(
suffixIcon: widget.passwordMode == true
? IconButton(
icon: Icon(
_obscureText
? Icons.visibility_off
: Icons.visibility,
color: widget.inputColor,
),
onPressed: () {
setState(() {
_obscureText = !_obscureText;
});
},
)
: null,
errorStyle: const TextStyle(
height: 0, fontSize: 0), // <-- Add this line
contentPadding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 8.0),
filled: true,
fillColor: widget.fillColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: field.hasError
? BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 2.0,
)
: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: field.hasError
? MzanziInnovationHub.of(context)!
.theme
.errorColor()
: widget.inputColor,
width: 3.0,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 3.0,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 3.0,
),
),
),
onChanged: (value) {
field.didChange(value);
},
),
), ),
), ),
if (field.hasError) ),
Row( ],
children: [ ),
Padding( const SizedBox(height: 4),
padding: const EdgeInsets.only(left: 8.0, top: 4.0), FormField<String>(
child: Text( initialValue: widget.controller.text,
field.errorText ?? '', validator: widget.validator,
style: TextStyle( autovalidateMode: AutovalidateMode.onUserInteraction,
fontSize: 12, builder: (field) {
color: MzanziInnovationHub.of(context)! _formFieldState = field;
.theme return Column(
.errorColor(), crossAxisAlignment:
fontWeight: FontWeight.bold, CrossAxisAlignment.start, // <-- Add this line
children: [
Material(
elevation: widget.elevation ?? 4.0,
borderRadius:
BorderRadius.circular(widget.borderRadius ?? 8.0),
child: SizedBox(
height:
widget.height != null ? widget.height! - 25 : null,
child: TextFormField(
controller: widget.controller,
cursorColor: widget.inputColor,
autofillHints: widget.autofillHints,
textAlign: TextAlign.start,
textAlignVertical: widget.multiLineInput == true
? TextAlignVertical.top
: TextAlignVertical.center,
obscureText: widget.passwordMode == true
? _obscureText
: false,
expands: widget.passwordMode == true
? false
: (widget.multiLineInput ?? false),
maxLines: widget.passwordMode == true ? 1 : null,
readOnly: widget.readOnly ?? false,
keyboardType: widget.numberMode == true
? TextInputType.number
: null,
inputFormatters: widget.numberMode == true
? [FilteringTextInputFormatter.digitsOnly]
: null,
style: TextStyle(
color: widget.inputColor,
fontWeight: FontWeight.w500,
),
decoration: InputDecoration(
suffixIcon: widget.passwordMode == true
? IconButton(
icon: Icon(
_obscureText
? Icons.visibility_off
: Icons.visibility,
color: widget.inputColor,
),
onPressed: () {
setState(() {
_obscureText = !_obscureText;
});
},
)
: null,
errorStyle: const TextStyle(
height: 0, fontSize: 0), // <-- Add this line
contentPadding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 8.0),
filled: true,
fillColor: widget.fillColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: field.hasError
? BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 2.0,
)
: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: field.hasError
? MzanziInnovationHub.of(context)!
.theme
.errorColor()
: widget.inputColor,
width: 3.0,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 3.0,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
widget.borderRadius ?? 8.0),
borderSide: BorderSide(
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
width: 3.0,
),
), ),
), ),
onChanged: (value) {
field.didChange(value);
},
), ),
], ),
), ),
], if (field.hasError)
); Row(
}, children: [
), Padding(
], padding: const EdgeInsets.only(left: 8.0, top: 4.0),
child: Text(
field.errorText ?? '',
style: TextStyle(
fontSize: 12,
color: MzanziInnovationHub.of(context)!
.theme
.errorColor(),
fontWeight: FontWeight.bold,
),
),
),
],
),
],
);
},
),
],
),
), ),
); );
} }