86 lines
2.4 KiB
Dart
86 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class CommonTextFormField extends StatelessWidget {
|
|
final String? hintText;
|
|
final TextEditingController? controller;
|
|
final String? Function(String?)? validator;
|
|
final bool obscureText;
|
|
final Widget? prefixIcon;
|
|
final Widget? suffixIcon;
|
|
final TextInputType? keyboardType;
|
|
final String? errorText;
|
|
final void Function(String)? onChanged;
|
|
final int? maxLines;
|
|
final int? minLines;
|
|
final bool expands;
|
|
|
|
const CommonTextFormField({
|
|
super.key,
|
|
this.hintText,
|
|
this.controller,
|
|
this.validator,
|
|
this.obscureText = false,
|
|
this.prefixIcon,
|
|
this.suffixIcon,
|
|
this.keyboardType,
|
|
this.errorText,
|
|
this.onChanged,
|
|
this.maxLines,
|
|
this.minLines,
|
|
this.expands = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bool isMultiline = (maxLines != null && maxLines! > 1) || expands;
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 360,
|
|
height: isMultiline ? null : 57.89,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16.28),
|
|
border: Border.all(
|
|
color: errorText != null ? Colors.red : const Color(0xFFBDBCBC),
|
|
width: 0.9,
|
|
),
|
|
),
|
|
child: TextFormField(
|
|
controller: controller,
|
|
validator: validator,
|
|
obscureText: obscureText,
|
|
keyboardType: keyboardType ??
|
|
(isMultiline ? TextInputType.multiline : TextInputType.text),
|
|
onChanged: onChanged,
|
|
maxLines: expands ? null : maxLines ?? 1,
|
|
minLines: expands ? null : minLines,
|
|
expands: expands,
|
|
decoration: InputDecoration(
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 18,
|
|
),
|
|
hintText: hintText,
|
|
border: InputBorder.none,
|
|
prefixIcon: prefixIcon,
|
|
suffixIcon: suffixIcon,
|
|
errorStyle: const TextStyle(height: 0),
|
|
),
|
|
),
|
|
),
|
|
if (errorText != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 16.0, top: 4.0),
|
|
child: Text(
|
|
errorText!,
|
|
style: const TextStyle(color: Colors.red, fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|