94 lines
2.9 KiB
Dart
94 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
class CommonTextFormField extends StatefulWidget {
|
|
final String title;
|
|
final String? label;
|
|
final TextEditingController? controller;
|
|
//final TextCapitalization textCapitalization;
|
|
final String? Function(String?)? validator;
|
|
final Color? fillColor;
|
|
final bool? readOnly;
|
|
final int? maxLines;
|
|
final double? height;
|
|
final TextInputType? keyboardType;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final int? maxLength;
|
|
final bool obscureText;
|
|
final void Function(String)? onChanged;
|
|
|
|
const CommonTextFormField({
|
|
super.key,
|
|
required this.title,
|
|
this.label,
|
|
this.controller,
|
|
this.validator,
|
|
this.fillColor,
|
|
this.readOnly,
|
|
this.maxLines,
|
|
this.height,
|
|
this.keyboardType,
|
|
this.inputFormatters,
|
|
this.maxLength,
|
|
this.onChanged,
|
|
// this.textCapitalization = TextCapitalization.sentences,
|
|
this.obscureText = false,
|
|
});
|
|
|
|
@override
|
|
_CommonTextFormFieldState createState() => _CommonTextFormFieldState();
|
|
}
|
|
|
|
class _CommonTextFormFieldState extends State<CommonTextFormField> {
|
|
bool _isObscured = true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
TextFormField(
|
|
controller: widget.controller,
|
|
//textCapitalization: widget.textCapitalization,
|
|
readOnly: widget.readOnly ?? false,
|
|
maxLines: widget.maxLines ?? 1,
|
|
maxLength: widget.maxLength,
|
|
onChanged: widget.onChanged,
|
|
onTapOutside: (event) => FocusScope.of(context).unfocus(),
|
|
validator: widget.validator,
|
|
keyboardType: widget.keyboardType,
|
|
inputFormatters: widget.inputFormatters,
|
|
obscureText: widget.obscureText && _isObscured,
|
|
decoration: InputDecoration(
|
|
hintText: widget.title,
|
|
labelText: widget.label,
|
|
contentPadding: const EdgeInsets.only(bottom: 10, left: 10),
|
|
filled: true,
|
|
suffixIcon: widget.obscureText
|
|
? IconButton(
|
|
icon: Icon(
|
|
_isObscured ? Icons.visibility : Icons.visibility_off,
|
|
color: Colors.grey,
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
_isObscured = !_isObscured;
|
|
});
|
|
},
|
|
)
|
|
: null,
|
|
focusedBorder: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
borderSide: BorderSide(color: Colors.transparent),
|
|
),
|
|
enabledBorder: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
borderSide: BorderSide(color: Colors.transparent),
|
|
),
|
|
fillColor: widget.fillColor ?? Colors.white,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|