79 lines
2.3 KiB
Dart
79 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
enum InputTypes { text, number }
|
|
|
|
class FormTextInput extends StatelessWidget {
|
|
const FormTextInput(
|
|
{super.key,
|
|
required this.controller,
|
|
required this.title,
|
|
this.icon,
|
|
this.maxLines,
|
|
this.minLines,
|
|
this.onTap,
|
|
this.requiresValidation = true,
|
|
this.type = InputTypes.text,
|
|
this.hint,
|
|
this.validations});
|
|
|
|
final TextEditingController controller;
|
|
final String title;
|
|
final int? maxLines;
|
|
final int? minLines;
|
|
final Icon? icon;
|
|
final dynamic onTap;
|
|
final bool requiresValidation;
|
|
final InputTypes type;
|
|
final String? hint;
|
|
final Function? validations;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Map params = {};
|
|
if (type == InputTypes.number) {
|
|
params['keyboardType'] = TextInputType.number;
|
|
params['inputFormatters'] = <TextInputFormatter>[
|
|
FilteringTextInputFormatter.digitsOnly
|
|
];
|
|
}
|
|
|
|
return Padding(
|
|
padding: EdgeInsets.only(top: 10, bottom: 10),
|
|
child: TextFormField(
|
|
keyboardType: params['keyboardType'] ?? TextInputType.text,
|
|
inputFormatters: params['inputFormatters'] ?? [],
|
|
minLines: minLines ?? 1,
|
|
maxLines: maxLines ?? 1,
|
|
controller: controller,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
prefixIcon: icon ?? Icon(Icons.draw_rounded),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide.none,
|
|
borderRadius: BorderRadius.circular(12)),
|
|
labelText: title,
|
|
hintText: hint ?? '',
|
|
),
|
|
validator: (String? value) {
|
|
if (requiresValidation == true) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Please enter some text';
|
|
}
|
|
|
|
if (validations != null) validations!(value);
|
|
|
|
// if (value.length < 3) {
|
|
// return 'Please enter a minimum of 3 characters';
|
|
// }
|
|
}
|
|
return null;
|
|
},
|
|
onTap: () {
|
|
if (onTap != null) {
|
|
onTap();
|
|
}
|
|
}));
|
|
}
|
|
}
|