class comInput extends StatelessWidget {
final TextEditingController controller;
final List<TextInputFormatter>? inputFormatters;
final String hintText;
final Widget? prewidget;
final Widget? suffwidget;
final TextInputType? keyType;
final bool? readOnly;
final bool? obscureText;
const comInput(
{super.key,
required this.controller,
this.inputFormatters,
required this.hintText,
this.prewidget,
this.suffwidget,
this.keyType,
this.readOnly = false,
this.obscureText = false});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 18, right: 18),
child: TextFormField(
controller: controller,
onEditingComplete: () {
FocusScope.of(context).unfocus();
},
keyboardType: keyType != null ? keyType : TextInputType.number,
textInputAction: TextInputAction.done,
readOnly: readOnly!,
obscureText: obscureText!,
obscuringCharacter: '⁙',
inputFormatters: inputFormatters != null
? inputFormatters
: [
LengthLimitingTextInputFormatter(50),
FilteringTextInputFormatter.allow(RegExp("[0-9.]"))
],
cursorColor: colorController.buttom.value.withOpacity(0.5),
decoration: InputDecoration(
contentPadding: EdgeInsets.all(12.0),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.red, width: 2)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
BorderSide(color: colorController.buttom.value, width: 2)),
hintText: hintText,
hintStyle: GoogleFonts.notoSans(
color: getIsDark(context) == true
? appColor.white.withOpacity(0.8)
: appColor.black.withOpacity(0.3)),
prefixIcon: prewidget != null
? Padding(
padding: const EdgeInsets.only(left: 6, right: 6),
child: prewidget,
)
: SizedBox(),
suffixIcon: suffwidget != null
? Padding(
padding: const EdgeInsets.only(left: 6, right: 6),
child: suffwidget,
)
: SizedBox(),
suffixIconConstraints: BoxConstraints(
maxHeight: 30,
maxWidth: 40,
),
prefixIconConstraints: BoxConstraints(
maxHeight: 30,
maxWidth: 40,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
)),
);
}
}
版权属于:
narakuyang
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论