Skip to content

Commit 94b9f26

Browse files
committed
Add decoration, update gif image
1 parent f49bbac commit 94b9f26

File tree

5 files changed

+72
-50
lines changed

5 files changed

+72
-50
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ import'package:flutter_verification_code_input/flutter_verification_code_input.d
2020
## Usage
2121

2222
```dart
23-
new VerificationCodeInput(
24-
keyboardType: TextInputType.number,
25-
length: 4,
26-
onCompleted: (String value) {
27-
//...
28-
print(value);
29-
},
30-
)
23+
VerificationCodeInput(
24+
keyboardType: TextInputType.number,
25+
length: 4,
26+
onCompleted: (String value) {
27+
//...
28+
print(value);
29+
},
30+
)
3131
```
3232

3333
## Showcase
3434

35-
![Showcase](show_case.gif)
35+
36+
![Showcase|100x100, 10%](show_case.gif)
37+
38+

example/lib/main.dart

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,47 @@ class MyHomePage extends StatefulWidget {
2323
}
2424

2525
class _MyHomePageState extends State<MyHomePage> {
26-
get key => null;
26+
String _onCompleted = "";
2727

2828
@override
2929
Widget build(BuildContext context) {
3030
return new Scaffold(
3131
appBar: new AppBar(
3232
title: Center(child: new Text('Example verify code')),
3333
),
34-
body: Center(
35-
child: Column(
34+
body: Container(
35+
child: ListView(
3636
children: <Widget>[
3737
Padding(
3838
padding: const EdgeInsets.all(8.0),
39-
child: Text('Enter your code', style: TextStyle(fontSize: 20.0),),
40-
),
41-
Expanded(
42-
flex: 1,
43-
child: VerificationCodeInput(
44-
keyboardType: TextInputType.number,
45-
length: 4,
46-
padding: EdgeInsets.only(left: 80, right: 80),
47-
onCompleted: (String value) {
48-
print(value);
49-
},
39+
child: Center(
40+
child: Text(
41+
'Enter your code',
42+
style: TextStyle(fontSize: 20.0),
43+
),
5044
),
5145
),
46+
VerificationCodeInput(
47+
keyboardType: TextInputType.number,
48+
length: 4,
49+
padding: EdgeInsets.only(left: 80, right: 80),
50+
onCompleted: (String value) {
51+
print(value);
52+
setState(() {
53+
_onCompleted = value;
54+
});
55+
},
56+
),
57+
(_onCompleted != "")
58+
? Padding(
59+
padding: const EdgeInsets.all(8.0),
60+
child: Center(
61+
child: Text(
62+
'Your code: $_onCompleted',
63+
),
64+
),
65+
)
66+
: Container(),
5267
],
5368
),
5469
),

lib/src/verification_code_input.dart

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

show_case.gif

100755100644
-501 KB
Loading

untitled.webm

1.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)