25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

184 satır
6.6 KiB

  1. // ignore_for_file: public_member_api_docs, sort_constructors_first
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:qadirneyriz/config/config.dart';
  5. import 'package:qadirneyriz/widgets/custom_button.dart';
  6. // ignore: must_be_immutable
  7. class CustomTextField extends StatefulWidget {
  8. final String label;
  9. final String hintText;
  10. final bool obscureText;
  11. final double contentPadding;
  12. final bool hasButton;
  13. final TextInputAction textInputAction;
  14. final TextEditingController textEditingController;
  15. final TextInputType textInputType;
  16. final int? maxLine;
  17. final Color? fillsColor;
  18. bool isReadOnly = false;
  19. final double paddingVertical;
  20. final double paddingHarizon;
  21. bool isPass = false;
  22. FocusNode? focus;
  23. IconData? firstIcon;
  24. final void Function(String s)? onChanged;
  25. final void Function()? buttonOnPressed;
  26. bool hasLable = true;
  27. CustomTextField({
  28. Key? key,
  29. required this.label,
  30. required this.hintText,
  31. this.obscureText = false,
  32. this.contentPadding = 10,
  33. this.hasButton = false,
  34. this.textInputAction = TextInputAction.done,
  35. required this.textEditingController,
  36. required this.textInputType,
  37. this.maxLine,
  38. this.fillsColor = Colors.white,
  39. this.isReadOnly = false,
  40. this.isPass = false,
  41. this.focus,
  42. this.firstIcon,
  43. this.onChanged,
  44. this.buttonOnPressed,
  45. this.hasLable = true,
  46. this.paddingVertical = 10,
  47. this.paddingHarizon = 20,
  48. }) : super(key: key);
  49. @override
  50. _CustomTextFieldState createState() => _CustomTextFieldState();
  51. }
  52. bool obscureText = true;
  53. class _CustomTextFieldState extends State<CustomTextField> {
  54. @override
  55. Widget build(BuildContext context) {
  56. return Padding(
  57. padding: EdgeInsets.symmetric(
  58. horizontal: widget.paddingHarizon, vertical: widget.paddingVertical),
  59. child: Column(
  60. crossAxisAlignment: CrossAxisAlignment.start,
  61. children: [
  62. widget.hasLable
  63. ? Padding(
  64. padding: const EdgeInsets.only(right: 5),
  65. child: Text(
  66. widget.label,
  67. style: TextStyle(
  68. fontWeight: FontWeight.normal,
  69. fontSize: 13,
  70. color: Colors.black.withOpacity(.8),
  71. ),
  72. ),
  73. )
  74. : Container(),
  75. SizedBox(height: widget.hasLable ? 6 : 0),
  76. Stack(
  77. children: [
  78. TextFormField(
  79. inputFormatters: [
  80. widget.textInputType == TextInputType.number
  81. ? FilteringTextInputFormatter.allow(
  82. RegExp('[a-z A-Z 0-9 ا-ی]'))
  83. : FilteringTextInputFormatter.singleLineFormatter
  84. ],
  85. readOnly: widget.isReadOnly,
  86. onFieldSubmitted: (v) {
  87. FocusScope.of(context).requestFocus(widget.focus);
  88. },
  89. onChanged: widget.onChanged,
  90. minLines: 1, // تعیین ارتفاع بر اساس تعداد خطوط
  91. maxLines: 1, // تعداد خطوط نامحدود
  92. controller: widget.textEditingController,
  93. keyboardType: widget.textInputType,
  94. textInputAction: widget.textInputAction,
  95. obscureText: (widget.isPass) ? obscureText : false,
  96. style: TextStyle(
  97. fontSize: 12,
  98. color: Colors.black.withOpacity(.5),
  99. ),
  100. decoration: InputDecoration(
  101. hintText: widget.hintText,
  102. hintStyle: TextStyle(
  103. color: config.ui.mainGray.withOpacity(.6),
  104. fontSize: 12),
  105. // filled: true,
  106. // fillColor: widget.fillsColor,
  107. enabledBorder: UnderlineInputBorder(
  108. borderSide: BorderSide(
  109. color:
  110. config.ui.mainGreen, // رنگ بردر پایین در حالت فعال
  111. width: 2, // ضخامت بردر پایین
  112. ),
  113. ),
  114. focusedBorder: UnderlineInputBorder(
  115. borderSide: BorderSide(
  116. color:
  117. config.ui.mainGreen, // رنگ بردر پایین در حالت فوکوس
  118. width: 2, // ضخامت بردر پایین
  119. ),
  120. ),
  121. prefixIcon: widget.firstIcon != null
  122. ? Row(
  123. mainAxisSize: MainAxisSize.min,
  124. mainAxisAlignment: MainAxisAlignment.center,
  125. children: [
  126. Icon(
  127. widget.firstIcon,
  128. color: config.ui.mainGreen,
  129. ),
  130. const SizedBox(
  131. width: 10,
  132. ),
  133. Container(
  134. color: config.ui.mainGreen,
  135. width: 1.5,
  136. height: 25,
  137. ),
  138. ],
  139. )
  140. : null,
  141. suffixIcon: (widget.isPass == true)
  142. ? InkWell(
  143. onTap: () {
  144. setState(() {
  145. obscureText = !obscureText;
  146. });
  147. },
  148. child: Icon(
  149. obscureText
  150. ? Icons.visibility_off
  151. : Icons.visibility,
  152. color: Colors.grey,
  153. ),
  154. )
  155. : null,
  156. contentPadding: EdgeInsets.all(widget.contentPadding)),
  157. ),
  158. widget.hasButton
  159. ? Positioned(
  160. left: 10,
  161. top: 10,
  162. child: Center(
  163. child: CustomButton(
  164. hieght: 35,
  165. width: 100,
  166. text: 'ثبت',
  167. onPressed: widget.buttonOnPressed,
  168. ),
  169. ))
  170. : Container()
  171. ],
  172. ),
  173. ],
  174. ),
  175. );
  176. }
  177. }