Skip to content

Commit 73e1689

Browse files
author
ProgrammerHasan
committed
TextFieldComponent
1 parent 0cbf17f commit 73e1689

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

lib/components/textfield.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'package:flutter/material.dart';
2+
3+
class TextFieldComponent extends StatefulWidget {
4+
final String hint;
5+
final TextEditingController controller;
6+
final Color color;
7+
final bool isEnable;
8+
final bool isAutoFocus;
9+
10+
TextFieldComponent({Key key, @required this.hint, @required this.controller, this.color,this.isEnable,this.isAutoFocus=false}) : super(key: key);
11+
12+
@override
13+
_TextFieldComponentState createState() => _TextFieldComponentState();
14+
}
15+
16+
class _TextFieldComponentState extends State<TextFieldComponent> {
17+
18+
@override
19+
void initState() {
20+
super.initState();
21+
widget.controller.addListener(() {
22+
if (widget.controller.text == 'null') {
23+
widget.controller.text = '';
24+
}
25+
});
26+
}
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return TextFormField(
31+
enabled: widget.isEnable??true,
32+
style: TextStyle(
33+
fontSize: 14
34+
),
35+
keyboardType: TextInputType.text,
36+
autofocus: widget.isAutoFocus,
37+
decoration: InputDecoration(
38+
errorStyle: TextStyle(color: Colors.red),
39+
focusColor: Colors.grey[700],
40+
enabledBorder: OutlineInputBorder(
41+
borderSide: BorderSide(
42+
color: Colors.grey[700],
43+
),
44+
),
45+
focusedBorder: OutlineInputBorder(
46+
borderSide: BorderSide(
47+
color: Colors.grey[700],
48+
width: 1.0,
49+
),
50+
),
51+
labelText: widget.hint,
52+
labelStyle: TextStyle(
53+
color: widget.color??Colors.grey[700],
54+
),
55+
border: OutlineInputBorder(),
56+
contentPadding: EdgeInsets.only(left: 8, right: 8),
57+
),
58+
controller: widget.controller,
59+
validator: (value) =>
60+
value.isEmpty ? 'Please enter password' : null
61+
);
62+
}
63+
}

0 commit comments

Comments
 (0)