2026-04-07 11:30:22 +02:00
|
|
|
// lib/ui/common/flux_text_field.dart
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flux/core/theme/theme.dart';
|
|
|
|
|
|
|
|
|
|
class FluxTextField extends StatelessWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final IconData icon;
|
|
|
|
|
final bool isPassword;
|
2026-04-10 11:34:11 +02:00
|
|
|
final bool autoFocus;
|
2026-04-07 11:30:22 +02:00
|
|
|
final TextEditingController? controller;
|
|
|
|
|
final TextInputType? keyboardType; // Aggiunto per flessibilità
|
2026-04-10 11:34:11 +02:00
|
|
|
final int? minLines;
|
|
|
|
|
final int? maxLines;
|
2026-04-13 11:01:50 +02:00
|
|
|
final Function(String)? onSubmitted;
|
2026-04-13 18:26:17 +02:00
|
|
|
final int? maxLenght;
|
|
|
|
|
final Function(String)? onChanged;
|
2026-04-07 11:30:22 +02:00
|
|
|
|
|
|
|
|
const FluxTextField({
|
|
|
|
|
super.key, // Usiamo super.key per Flutter moderno
|
|
|
|
|
required this.label,
|
|
|
|
|
required this.icon,
|
|
|
|
|
this.isPassword = false,
|
2026-04-10 11:34:11 +02:00
|
|
|
this.autoFocus = false,
|
2026-04-07 11:30:22 +02:00
|
|
|
this.controller,
|
|
|
|
|
this.keyboardType,
|
2026-04-10 11:34:11 +02:00
|
|
|
this.minLines,
|
|
|
|
|
this.maxLines = 1,
|
2026-04-13 11:01:50 +02:00
|
|
|
this.onSubmitted,
|
2026-04-13 18:26:17 +02:00
|
|
|
this.maxLenght,
|
|
|
|
|
this.onChanged,
|
2026-04-07 11:30:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return TextField(
|
|
|
|
|
controller: controller,
|
|
|
|
|
obscureText: isPassword,
|
|
|
|
|
keyboardType: keyboardType,
|
2026-04-10 11:34:11 +02:00
|
|
|
autofocus: autoFocus,
|
|
|
|
|
minLines: minLines,
|
|
|
|
|
// Se minLines è impostato, maxLines deve essere almeno uguale o null (espandibile)
|
|
|
|
|
maxLines: minLines != null ? null : maxLines,
|
2026-04-07 11:30:22 +02:00
|
|
|
style: TextStyle(color: context.primaryText),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
prefixIcon: Icon(icon, color: context.accent.withValues(alpha: 0.6)),
|
|
|
|
|
labelText: label,
|
|
|
|
|
labelStyle: TextStyle(color: context.secondaryText, fontSize: 14),
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: context.surface.withValues(alpha: 0.5),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
borderSide: BorderSide(
|
|
|
|
|
color: context.secondaryText.withValues(alpha: 0.1),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
borderSide: BorderSide(color: context.accent, width: 1.5),
|
|
|
|
|
),
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 16,
|
|
|
|
|
vertical: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-04-13 11:01:50 +02:00
|
|
|
onSubmitted: onSubmitted,
|
2026-04-13 18:26:17 +02:00
|
|
|
onChanged: onChanged,
|
|
|
|
|
maxLength: maxLenght,
|
2026-04-07 11:30:22 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|