Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.0 kB
0
Indexable
Never
import 'package:emi_calculator_app/common_widgets/style.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../constant/app_color.dart';

class CommonField extends StatelessWidget {
  final TextEditingController? textEditingController;
  final int? maxLines;
  final int? maxLength;
  final double? width;
  final double? height;
  final double? margin;
  final Widget? suffixIcon;
  final EdgeInsets? contentPadding;
  final String? hintText;
  final BorderRadius? borderRadius;
  final TextInputType? keyboardType;
  final void Function(Object?)? onChanged;
  final VoidCallback? onEditingComplete;
  final String? Function(String?)? validator;
  final String? Function(String?)? onFieldSubmitted;

  const CommonField(
      {Key? key,
      this.textEditingController,
      this.maxLines,
      this.maxLength,
      this.suffixIcon,
      this.keyboardType,
      this.onChanged,
      this.validator,
      this.hintText,
      this.contentPadding,
      this.borderRadius,
      this.width,
      this.height,
      this.onEditingComplete,
      this.onFieldSubmitted,
      this.margin})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        width: width,
        height: height,
        margin: EdgeInsets.only(top: margin ?? 15),
        child: TextFormField(
            controller: textEditingController,
            decoration: InputDecoration(
                hintText: hintText,
                hintStyle: AppStyle.hintTxt(fontSize: 15),
                contentPadding: contentPadding ??
                    EdgeInsets.symmetric(vertical: 10.0, horizontal: 10),
                suffixIcon: suffixIcon,
                filled: true,
                counterText: '',
                fillColor: AppColor.lightBg,
                focusedBorder: OutlineInputBorder(
                    borderRadius: borderRadius ?? BorderRadius.circular(8.0),
                    borderSide: BorderSide(color: AppColor.lightBg)),
                disabledBorder: OutlineInputBorder(
                    borderRadius: borderRadius ?? BorderRadius.circular(8.0),
                    borderSide: BorderSide(color: AppColor.lightBg)),
                enabledBorder: OutlineInputBorder(
                    borderRadius: borderRadius ?? BorderRadius.circular(8.0),
                    borderSide: BorderSide(color: AppColor.lightBg)),
                border: InputBorder.none),
            keyboardType: keyboardType ?? TextInputType.number,
            style: AppStyle.whiteTxt(fontSize: 15),
            maxLines: maxLines,
            maxLength: maxLength,
            onChanged: onChanged,
            onEditingComplete: onEditingComplete,
            onFieldSubmitted: onFieldSubmitted,
            validator: validator,
            cursorColor: AppColor.background,
            inputFormatters: [
              LengthLimitingTextInputFormatter(maxLength),
              FilteringTextInputFormatter.digitsOnly
            ]));
  }
}
Leave a Comment