text_input_field_widget.dart
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class TextInputFieldWidget extends StatefulWidget {
final String hintText;
final ValueChanged<String>? textChanged;
final bool obscureText;
final Color hasFocusColor;
final Color hitColor;
final double fontSize;
final int maxLines;
final double lineHeight;
final List<TextInputFormatter>? textInputFormatters;
final ValueChanged<String>? onChanged;
final TextEditingController? textEditingController;
final FocusNode? focusNode;
const TextInputFieldWidget(
{Key? key,
this.hintText = "",
this.textChanged,
this.obscureText = false,
this.hasFocusColor = const Color(0xFF303133),
this.hitColor = const Color(0xFFC0C4CC),
this.fontSize = 14,
this.lineHeight = 1,
this.maxLines = 1,
this.onChanged,
this.textInputFormatters,
this.textEditingController,
this.focusNode})
: super(key: key);
@override
State<StatefulWidget> createState() {
return _TextInputFieldWidgetState();
}
}
class _TextInputFieldWidgetState extends State<TextInputFieldWidget> {
String inputText = "";
@override
void initState() {
widget.textEditingController!.addListener(_handleTextInput);
super.initState();
}
void _handleTextInput() {
widget.textChanged?.call(widget.textEditingController!.text);
setState(() {
inputText = widget.textEditingController!.text;
});
}
@override
Widget build(BuildContext context) {
return TextField(
focusNode: widget.focusNode,
maxLines: widget.maxLines,
controller: widget.textEditingController,
obscureText: widget.obscureText,
onChanged: widget.onChanged,
inputFormatters: [...?widget.textInputFormatters],
style: TextStyle(
fontSize: widget.fontSize,
height: widget.lineHeight,
color: widget.hasFocusColor),
decoration: InputDecoration(
hintText: widget.hintText,
// border: InputBorder.none,
hintStyle: TextStyle(
color: widget.hitColor,
height: widget.lineHeight,
fontSize: widget.fontSize,
),
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(borderSide: BorderSide.none),
),
);
}
@override
void dispose() {
super.dispose();
}
}