79 lines
2.2 KiB
Dart
79 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:barber_app/core/theme/app_theme.dart';
|
|
|
|
class CustomTextField extends StatelessWidget {
|
|
final TextEditingController controller;
|
|
final String label;
|
|
final String? hint;
|
|
final IconData? prefixIcon;
|
|
final Widget? suffixIcon;
|
|
final bool obscureText;
|
|
final TextInputType? keyboardType;
|
|
final String? Function(String?)? validator;
|
|
final int maxLines;
|
|
final void Function(String)? onChanged;
|
|
final TextCapitalization textCapitalization;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
|
|
const CustomTextField({
|
|
super.key,
|
|
required this.controller,
|
|
required this.label,
|
|
this.hint,
|
|
this.prefixIcon,
|
|
this.suffixIcon,
|
|
this.obscureText = false,
|
|
this.keyboardType,
|
|
this.validator,
|
|
this.maxLines = 1,
|
|
this.onChanged,
|
|
this.textCapitalization = TextCapitalization.none,
|
|
this.inputFormatters,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
final textColor = isDark ? AppColors.textPrimary : Colors.black87;
|
|
final labelColor = isDark ? AppColors.textSecondary : Colors.black54;
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: labelColor,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
TextFormField(
|
|
controller: controller,
|
|
obscureText: obscureText,
|
|
keyboardType: keyboardType,
|
|
validator: validator,
|
|
maxLines: maxLines,
|
|
onChanged: onChanged,
|
|
textCapitalization: textCapitalization,
|
|
inputFormatters: inputFormatters,
|
|
style: TextStyle(
|
|
color: textColor,
|
|
fontSize: 16,
|
|
),
|
|
decoration: InputDecoration(
|
|
hintText: hint,
|
|
prefixIcon: prefixIcon != null
|
|
? Icon(prefixIcon, color: labelColor)
|
|
: null,
|
|
suffixIcon: suffixIcon,
|
|
hintStyle: TextStyle(color: isDark ? Colors.white38 : Colors.black38),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|