import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:tangheem/classes/colors.dart';

class CommonTextFieldWidget extends StatelessWidget {
  final String hint;
  final TextEditingController controller;
  final bool isPassword;
  final String prefixIcon;
  final Widget suffixWidget;
  final Function onTap;
  final int maxLines;
  final FocusNode focusNode;

  CommonTextFieldWidget({Key key, @required this.hint, @required this.controller, this.maxLines = 1, this.focusNode, this.isPassword = false, this.prefixIcon, this.suffixWidget, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: TextField(
        textAlignVertical: TextAlignVertical.center,
        controller: controller,
        obscureText: isPassword,
        textInputAction: TextInputAction.next,
        style: TextStyle(color: ColorConsts.primaryBlack, fontSize: 14),
        cursorColor: ColorConsts.primaryBlue,
        readOnly: onTap != null,
        maxLines: maxLines,
        onTap: onTap,
        focusNode: focusNode,
        scrollPhysics: BouncingScrollPhysics(),
        decoration: InputDecoration(
          contentPadding: EdgeInsets.fromLTRB(4, 4, 8, 4),
          alignLabelWithHint: true,
          fillColor: Colors.white,
          filled: true,
          hintStyle: TextStyle(color: ColorConsts.textGrey2, fontSize: 14),
          hintText: hint,
          suffixIcon: suffixWidget == null
              ? null
              : Padding(
                  padding: EdgeInsets.only(left: 8, right: 0),
                  child: suffixWidget,
                ),
          suffixIconConstraints: suffixWidget == null ? null : BoxConstraints(maxHeight: 30),
          prefixIconConstraints: prefixIcon == null ? prefixIcon : BoxConstraints(maxHeight: 18),
          prefixIcon: prefixIcon == null
              ? prefixIcon
              : Padding(
                  padding: EdgeInsets.only(left: 4, right: 0),
                  child: SvgPicture.asset(prefixIcon, color: ColorConsts.textGrey2),
                ),
          border: OutlineInputBorder(borderRadius: BorderRadius.circular(6), borderSide: BorderSide.none),
        ),
      ),
    );
  }
}
