diff --git a/packages/core/lib/presentation/widget/inputs/input_fixed_hint.dart b/packages/core/lib/presentation/widget/inputs/input_fixed_hint.dart new file mode 100644 index 0000000..ad4004b --- /dev/null +++ b/packages/core/lib/presentation/widget/inputs/input_fixed_hint.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; + +import '../../common/app_color.dart'; +import '../../common/app_fonts.dart' show AppFonts; + +enum InputType { text, number, email, password } + +class TextFiledFixedHint extends StatefulWidget { + const TextFiledFixedHint({ + super.key, + required this.hintText, + required this.onChanged, + this.inputType = InputType.text, + this.initialValue, + this.controller, + this.keyboardType, + this.textInputAction, + this.enabled, + this.readOnly, + this.maxLines, + this.minLines, + }); + + final String hintText; + final InputType inputType; + + final ValueChanged? onChanged; + final String? initialValue; + final TextEditingController? controller; + final TextInputType? keyboardType; + final TextInputAction? textInputAction; + final bool? enabled; + final bool? readOnly; + final int? maxLines; + final int? minLines; + + @override + State createState() => _TextFiledFixedHintState(); +} + +class _TextFiledFixedHintState extends State { + TextEditingController? tmpController; + + @override + void initState() { + super.initState(); + if (widget.controller == null) { + tmpController = TextEditingController(text: widget.initialValue); + if (widget.initialValue != null) { + tmpController?.text = widget.initialValue!; + } + } else { + tmpController = widget.controller; + } + } + + @override + Widget build(BuildContext context) { + return Container( + height: 40, + width: MediaQuery.of(context).size.width, + padding: const EdgeInsets.symmetric(horizontal: 12), + decoration: BoxDecoration( + border: Border.all(color: AppColor.darkGreyLight), + borderRadius: BorderRadius.circular(8), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(top: 3), + child: Text(widget.hintText, style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyNormalActive)), + ), + Expanded( + child: TextField( + controller: tmpController, + keyboardType: widget.inputType == InputType.number ? TextInputType.number : widget.keyboardType, + textInputAction: widget.textInputAction, + onChanged: widget.onChanged, + enabled: widget.enabled, + readOnly: widget.readOnly ?? false, + maxLines: widget.maxLines ?? 1, + minLines: widget.minLines ?? 1, + cursorHeight: 25, + textAlignVertical: TextAlignVertical.top, + obscureText: widget.inputType == InputType.password, + textAlign: widget.inputType == InputType.number ? TextAlign.start : TextAlign.start, + textDirection: widget.inputType == InputType.number ? TextDirection.ltr : TextDirection.rtl, + style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyNormalActive), + decoration: InputDecoration(border: InputBorder.none), + ), + ), + ], + ), + ); + } +}