Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:module_core/module_core.dart';
- import 'package:module_dependencies/module_dependencies_ui.dart';
- class CustomTextField extends StatefulWidget {
- const CustomTextField({
- Key? key,
- this.controller,
- this.textName,
- this.labelText,
- this.label,
- this.hintText,
- this.prefix,
- this.prefixIcon,
- this.suffixIcon,
- this.keyboardType,
- this.validator,
- this.inputFormatters,
- this.onChanged,
- this.onEditingComplete,
- this.onFieldSubmitted,
- this.textAlign = TextAlign.start,
- this.style,
- this.maxLength,
- this.minLines,
- this.maxLines,
- this.underlined = true,
- this.onTap,
- this.readOnly = false,
- this.fillColor,
- this.textInputAction,
- this.isObsecure = false,
- }) : super(key: key);
- final TextEditingController? controller;
- final String? textName;
- final Color? fillColor;
- final String? labelText;
- final Widget? label;
- final String? hintText;
- final Widget? prefix;
- final Widget? prefixIcon;
- final Widget? suffixIcon;
- final TextInputType? keyboardType;
- final String? Function(String?)? validator;
- final List<TextInputFormatter>? inputFormatters;
- final void Function(String)? onChanged;
- final void Function()? onEditingComplete;
- final void Function(String)? onFieldSubmitted;
- final TextAlign textAlign;
- final TextStyle? style;
- final int? maxLength;
- final int? minLines;
- final int? maxLines;
- final bool underlined;
- final void Function()? onTap;
- final bool readOnly;
- final TextInputAction? textInputAction;
- final bool isObsecure;
- @override
- State<CustomTextField> createState() => _CustomTextFieldState();
- }
- class _CustomTextFieldState extends State<CustomTextField> {
- OutlineInputBorder get _border => OutlineInputBorder(
- borderRadius: const BorderRadius.all(Radius.circular(12)),
- borderSide: BorderSide(
- width: 1.5,
- color:
- widget.underlined ? const Color(0xFFFF7226) : Colors.transparent,
- ),
- );
- OutlineInputBorder get _enabledBorder => OutlineInputBorder(
- borderRadius: const BorderRadius.all(Radius.circular(12)),
- borderSide: BorderSide(
- width: 1.5,
- color: widget.underlined ? colorBlack60 : Colors.transparent,
- ),
- );
- OutlineInputBorder get _errorBorder => OutlineInputBorder(
- borderRadius: const BorderRadius.all(Radius.circular(12)),
- borderSide: BorderSide(
- width: 1.5,
- color: widget.underlined ? colorDanger : Colors.transparent,
- ),
- );
- Widget eyeHiddenIcon = SizedBox(
- width: 20,
- height: 20,
- child: SvgPicture.asset(
- Assets.svg.eyeHide,
- fit: BoxFit.fitWidth,
- ),
- );
- Widget eyeShowIcon = SizedBox(
- height: 20,
- width: 20,
- child: SvgPicture.asset(
- Assets.svg.eyeShow,
- fit: BoxFit.fitWidth,
- ),
- );
- bool obsureText = false;
- @override
- void initState() {
- super.initState();
- setState(() {
- if (widget.isObsecure == true) {
- obsureText = true;
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- if (widget.textName != null)
- Padding(
- padding: const EdgeInsets.only(left: 16.0),
- child: Text(
- widget.textName ?? 'textName',
- style: GoogleFonts.inter(
- fontSize: 12.sp,
- fontWeight: FontWeight.w400,
- color: const Color(0xFF000000),
- ),
- ),
- ),
- if (widget.textName != null) const Gap(8),
- ClipRRect(
- borderRadius: const BorderRadius.all(Radius.circular(8)),
- child: TextFormField(
- validator: widget.validator,
- keyboardType: widget.keyboardType,
- maxLength: widget.maxLength,
- maxLines: widget.isObsecure == true ? 1 : widget.maxLines,
- minLines: widget.minLines,
- style: widget.style ??
- GoogleFonts.inter(
- fontSize: 14,
- fontWeight: FontWeight.w400,
- color: widget.readOnly == true
- ? Colors.grey
- : const Color(0xFF2D2F2E),
- ),
- obscureText: obsureText,
- textAlign: widget.textAlign,
- cursorColor: const Color(0xFF2D2F2E),
- controller: widget.controller,
- inputFormatters: widget.inputFormatters,
- onChanged: widget.onChanged,
- onTap: widget.onTap,
- readOnly: widget.readOnly,
- onEditingComplete: widget.onEditingComplete,
- onFieldSubmitted: widget.onFieldSubmitted,
- textInputAction: widget.textInputAction,
- textAlignVertical:
- (widget.prefixIcon != null || widget.suffixIcon != null)
- ? TextAlignVertical.center
- : null,
- decoration: InputDecoration(
- labelText: widget.labelText,
- hintText: widget.hintText,
- label: widget.label,
- prefix: widget.prefix,
- prefixIcon: widget.prefixIcon,
- suffixIcon: (widget.isObsecure == true)
- ? IconButton(
- splashRadius: 1,
- icon: (obsureText == true) ? eyeShowIcon : eyeHiddenIcon,
- onPressed: () {
- setState(() {
- obsureText = !obsureText;
- });
- },
- )
- : widget.suffixIcon,
- labelStyle: GoogleFonts.inter(
- fontSize: 14,
- fontWeight: FontWeight.w400,
- color: const Color(0xFF2D2F2E),
- ),
- hintStyle: GoogleFonts.inter(
- fontSize: 14,
- fontWeight: FontWeight.w400,
- color: const Color(0xFFC4C4C4),
- fontStyle: FontStyle.italic,
- ),
- filled: true,
- isDense: true,
- fillColor: widget.fillColor ?? const Color(0xFFFFFFFF),
- focusedBorder: _border,
- enabledBorder: _enabledBorder,
- border: _border,
- errorBorder: _errorBorder,
- ),
- ),
- ),
- ],
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement