add some components for settings later
This commit is contained in:
parent
e55d7c4c58
commit
274435b83e
2 changed files with 134 additions and 0 deletions
80
lib/widgets/form_text_input.dart
Normal file
80
lib/widgets/form_text_input.dart
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter/services.dart";
|
||||
|
||||
class FormTextInput extends StatelessWidget {
|
||||
final List<String? Function(String value)> extraValidators;
|
||||
final TextEditingController? controller;
|
||||
final TextInputType keyboardType;
|
||||
final String? initialValue;
|
||||
final bool readOnly;
|
||||
final bool obscure;
|
||||
final String? title;
|
||||
final int? minLines;
|
||||
final int? maxLength;
|
||||
final bool outlined;
|
||||
final int? maxLines;
|
||||
final bool capitalize;
|
||||
final bool required;
|
||||
final bool autocorrect;
|
||||
final void Function()? onTap;
|
||||
final Widget? trailing;
|
||||
final InputBorder? border;
|
||||
final List<TextInputFormatter>? formatters;
|
||||
|
||||
const FormTextInput({
|
||||
super.key,
|
||||
this.border,
|
||||
this.controller,
|
||||
this.title,
|
||||
this.obscure = false,
|
||||
this.readOnly = false,
|
||||
this.extraValidators = const [],
|
||||
this.keyboardType = TextInputType.text,
|
||||
this.initialValue,
|
||||
this.minLines,
|
||||
this.capitalize = false,
|
||||
this.maxLength,
|
||||
this.formatters,
|
||||
this.maxLines = 1,
|
||||
this.outlined = true,
|
||||
this.trailing,
|
||||
this.onTap,
|
||||
this.autocorrect = true,
|
||||
this.required = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
readOnly: readOnly,
|
||||
minLines: minLines,
|
||||
maxLines: maxLines,
|
||||
maxLength: maxLength,
|
||||
inputFormatters: formatters,
|
||||
textCapitalization: capitalize
|
||||
? TextCapitalization.sentences
|
||||
: TextCapitalization.none,
|
||||
initialValue: initialValue,
|
||||
autocorrect: autocorrect,
|
||||
obscureText: obscure,
|
||||
onTap: onTap,
|
||||
decoration: InputDecoration(
|
||||
labelText: title,
|
||||
border: border ?? (outlined ? null : const UnderlineInputBorder()),
|
||||
suffixIcon: trailing,
|
||||
),
|
||||
validator: (value) {
|
||||
if ((value?.isEmpty ?? true) && required) {
|
||||
return "This field is required";
|
||||
}
|
||||
|
||||
for (final validator in extraValidators) {
|
||||
final reason = validator(value!);
|
||||
if (reason != null) return reason;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue