@@ -5,13 +5,16 @@ class VerificationCodeInput extends StatefulWidget {
55 final TextInputType keyboardType;
66 final int length;
77 EdgeInsetsGeometry padding;
8- VerificationCodeInput ({
9- Key key,
10- this .onCompleted,
11- this .keyboardType,
12- this .length = 4 ,
13- this .padding = const EdgeInsets .all (8.0 ),
14- }) : super (key: key);
8+ BoxDecoration decoration;
9+
10+ VerificationCodeInput (
11+ {Key key,
12+ this .onCompleted,
13+ this .keyboardType,
14+ this .length = 4 ,
15+ this .padding = const EdgeInsets .all (8.0 ),
16+ this .decoration})
17+ : super (key: key);
1518
1619 @override
1720 _VerificationCodeInputState createState () =>
@@ -26,7 +29,6 @@ class _VerificationCodeInputState extends State<VerificationCodeInput> {
2629
2730 @override
2831 void initState () {
29- // _code[1] = '1'
3032 if (_listFocusNode.isEmpty) {
3133 for (var i = 0 ; i < widget.length; i++ ) {
3234 _listFocusNode.add (new FocusNode ());
@@ -40,10 +42,10 @@ class _VerificationCodeInputState extends State<VerificationCodeInput> {
4042 String _getInputVerify () {
4143 String verifycode = '' ;
4244 for (var i = 0 ; i < widget.length; i++ ) {
43- for (var index = 0 ; index < _listControllerText[i].text.length; index ++ ){
44- if (_listControllerText[i].text[index] != ' ' ) {
45+ for (var index = 0 ; index < _listControllerText[i].text.length; index++ ) {
46+ if (_listControllerText[i].text[index] != ' ' ) {
4547 verifycode += _listControllerText[i].text[index];
46- }
48+ }
4749 }
4850 }
4951 return verifycode;
@@ -64,7 +66,6 @@ class _VerificationCodeInputState extends State<VerificationCodeInput> {
6466 onChanged: (String value) {
6567 if (value.length > 1 && index < widget.length ||
6668 index == 0 && value.isNotEmpty) {
67-
6869 if (index == widget.length - 1 ) {
6970 widget.onCompleted (_getInputVerify ());
7071 return ;
@@ -117,22 +118,25 @@ class _VerificationCodeInputState extends State<VerificationCodeInput> {
117118 }
118119 }
119120
121+ List <Widget > _buildListWidget () {
122+ List <Widget > listWidget = List ();
123+ for (int index = 0 ; index < widget.length; index++ ) {
124+ listWidget.add (Container (
125+ height: 60 ,
126+ width: 60 ,
127+ padding: EdgeInsets .all (8.0 ),
128+ child: _buildInputItem (index)));
129+ }
130+ return listWidget;
131+ }
132+
120133 @override
121134 Widget build (BuildContext context) {
122- return Padding (
123- padding: widget.padding,
124- child: ListView .builder (
125- scrollDirection: Axis .horizontal,
126- itemCount: widget.length,
127- itemBuilder: (BuildContext context, int index) {
128- return SizedBox (
129- height: 60 ,
130- width: 60 ,
131- child: Container (
132- padding: EdgeInsets .all (8.0 ), child: _buildInputItem (index)),
133- );
134- },
135- ),
136- );
135+ return Container (
136+ decoration: widget.decoration,
137+ padding: widget.padding,
138+ child: Row (
139+ children: _buildListWidget (),
140+ ));
137141 }
138142}
0 commit comments