You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

206 lines
4.1 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:michele_s_application8/core/app_export.dart';
  3. class CustomTextFormField extends StatelessWidget {
  4. CustomTextFormField(
  5. {this.shape,
  6. this.padding,
  7. this.variant,
  8. this.fontStyle,
  9. this.alignment,
  10. this.width,
  11. this.margin,
  12. this.controller,
  13. this.focusNode,
  14. this.isObscureText = false,
  15. this.textInputAction = TextInputAction.next,
  16. this.textInputType = TextInputType.text,
  17. this.maxLines,
  18. this.hintText,
  19. this.prefix,
  20. this.prefixConstraints,
  21. this.suffix,
  22. this.suffixConstraints,
  23. this.validator});
  24. TextFormFieldShape? shape;
  25. TextFormFieldPadding? padding;
  26. TextFormFieldVariant? variant;
  27. TextFormFieldFontStyle? fontStyle;
  28. Alignment? alignment;
  29. double? width;
  30. EdgeInsetsGeometry? margin;
  31. TextEditingController? controller;
  32. FocusNode? focusNode;
  33. bool? isObscureText;
  34. TextInputAction? textInputAction;
  35. TextInputType? textInputType;
  36. int? maxLines;
  37. String? hintText;
  38. Widget? prefix;
  39. BoxConstraints? prefixConstraints;
  40. Widget? suffix;
  41. BoxConstraints? suffixConstraints;
  42. FormFieldValidator<String>? validator;
  43. @override
  44. Widget build(BuildContext context) {
  45. return alignment != null
  46. ? Align(
  47. alignment: alignment ?? Alignment.center,
  48. child: _buildTextFormFieldWidget(),
  49. )
  50. : _buildTextFormFieldWidget();
  51. }
  52. _buildTextFormFieldWidget() {
  53. return Container(
  54. width: width ?? double.maxFinite,
  55. margin: margin,
  56. child: TextFormField(
  57. controller: controller,
  58. focusNode: focusNode,
  59. style: _setFontStyle(),
  60. obscureText: isObscureText!,
  61. textInputAction: textInputAction,
  62. keyboardType: textInputType,
  63. maxLines: maxLines ?? 1,
  64. decoration: _buildDecoration(),
  65. validator: validator,
  66. ),
  67. );
  68. }
  69. _buildDecoration() {
  70. return InputDecoration(
  71. hintText: hintText ?? "",
  72. hintStyle: _setFontStyle(),
  73. border: _setBorderStyle(),
  74. enabledBorder: _setBorderStyle(),
  75. focusedBorder: _setBorderStyle(),
  76. disabledBorder: _setBorderStyle(),
  77. prefixIcon: prefix,
  78. prefixIconConstraints: prefixConstraints,
  79. suffixIcon: suffix,
  80. suffixIconConstraints: suffixConstraints,
  81. fillColor: _setFillColor(),
  82. filled: _setFilled(),
  83. isDense: true,
  84. contentPadding: _setPadding(),
  85. );
  86. }
  87. _setFontStyle() {
  88. switch (fontStyle) {
  89. default:
  90. return TextStyle(
  91. color: ColorConstant.gray500,
  92. fontSize: getFontSize(
  93. 13.24,
  94. ),
  95. fontFamily: 'Roboto',
  96. fontWeight: FontWeight.w400,
  97. height: getVerticalSize(
  98. 1.21,
  99. ),
  100. );
  101. }
  102. }
  103. _setOutlineBorderRadius() {
  104. switch (shape) {
  105. default:
  106. return BorderRadius.circular(
  107. getHorizontalSize(
  108. 20.00,
  109. ),
  110. );
  111. }
  112. }
  113. _setBorderStyle() {
  114. switch (variant) {
  115. case TextFormFieldVariant.None:
  116. return InputBorder.none;
  117. default:
  118. return OutlineInputBorder(
  119. borderRadius: _setOutlineBorderRadius(),
  120. borderSide: BorderSide(
  121. color: ColorConstant.gray300,
  122. width: 1,
  123. ),
  124. );
  125. }
  126. }
  127. _setFillColor() {
  128. switch (variant) {
  129. default:
  130. return ColorConstant.whiteA700;
  131. }
  132. }
  133. _setFilled() {
  134. switch (variant) {
  135. case TextFormFieldVariant.None:
  136. return false;
  137. default:
  138. return true;
  139. }
  140. }
  141. _setPadding() {
  142. switch (padding) {
  143. case TextFormFieldPadding.PaddingT13:
  144. return getPadding(
  145. left: 13,
  146. top: 13,
  147. bottom: 13,
  148. );
  149. default:
  150. return getPadding(
  151. left: 12,
  152. top: 14,
  153. right: 12,
  154. bottom: 14,
  155. );
  156. }
  157. }
  158. }
  159. enum TextFormFieldShape {
  160. RoundedBorder20,
  161. }
  162. enum TextFormFieldPadding {
  163. PaddingT14,
  164. PaddingT13,
  165. }
  166. enum TextFormFieldVariant {
  167. None,
  168. OutlineGray300,
  169. }
  170. enum TextFormFieldFontStyle {
  171. RobotoRomanRegular1324,
  172. }