Skip to content

Commit b323d62

Browse files
committed
Add verification page
1 parent 36b3a17 commit b323d62

File tree

4 files changed

+166
-3
lines changed

4 files changed

+166
-3
lines changed

assets/email.png

16.3 KB
Loading

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'package:example/animated_container.dart';
2-
import 'package:example/fade_animation.dart';
2+
import 'package:example/pages/verification.dart';
33
import 'package:flutter/material.dart';
44

55
void main() => runApp(
66
MaterialApp(
77
debugShowCheckedModeBanner: false,
8-
home: HomePage(),
8+
home: Verificatoin(),
99
)
1010
);
1111

lib/pages/verification.dart

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_verification_code/flutter_verification_code.dart';
3+
import 'dart:async';
4+
5+
class Verificatoin extends StatefulWidget {
6+
const Verificatoin({ Key? key }) : super(key: key);
7+
8+
@override
9+
_VerificatoinState createState() => _VerificatoinState();
10+
}
11+
12+
class _VerificatoinState extends State<Verificatoin> {
13+
bool _onEditing = true;
14+
bool _isResendAgain = false;
15+
bool _isVerified = false;
16+
bool _isLoading = false;
17+
18+
String _code = '';
19+
20+
@override
21+
void initState() {
22+
super.initState();
23+
}
24+
25+
late Timer _timer;
26+
int _start = 60;
27+
28+
void startTimer() {
29+
setState(() {
30+
_isResendAgain = true;
31+
});
32+
33+
const oneSec = const Duration(seconds: 1);
34+
_timer = new Timer.periodic(
35+
oneSec,
36+
(Timer timer) {
37+
setState(() {
38+
if (_start == 0) {
39+
_start = 60;
40+
_isResendAgain = false;
41+
timer.cancel();
42+
} else {
43+
_start--;
44+
}
45+
});
46+
},
47+
);
48+
}
49+
50+
verify() {
51+
setState(() {
52+
_isLoading = true;
53+
});
54+
55+
const oneSec = const Duration(milliseconds: 1000);
56+
_timer = new Timer.periodic(
57+
oneSec,
58+
(Timer timer) {
59+
setState(() {
60+
_isLoading = false;
61+
_isVerified = true;
62+
});
63+
},
64+
);
65+
}
66+
67+
@override
68+
Widget build(BuildContext context) {
69+
return Scaffold(
70+
backgroundColor: Colors.white,
71+
body: SingleChildScrollView(
72+
child: Container(
73+
height: MediaQuery.of(context).size.height,
74+
width: double.infinity,
75+
padding: EdgeInsets.symmetric(horizontal: 20),
76+
child: Column(
77+
mainAxisAlignment: MainAxisAlignment.center,
78+
crossAxisAlignment: CrossAxisAlignment.center,
79+
children: [
80+
Container(
81+
width: 200,
82+
height: 200,
83+
padding: EdgeInsets.all(20),
84+
decoration: BoxDecoration(
85+
shape: BoxShape.circle,
86+
color: Colors.grey.shade200
87+
),
88+
child: Transform.rotate(
89+
angle: 38,
90+
child: Image(
91+
image: AssetImage('assets/email.png'),
92+
),
93+
),
94+
),
95+
SizedBox(height: 80),
96+
Text("Verification", style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),),
97+
SizedBox(height: 30,),
98+
Text("Please enter the 6 digit code sent to \n +93 706-399-999",
99+
textAlign: TextAlign.center,
100+
style: TextStyle(fontSize: 16, height: 1.5, color: Colors.grey.shade500),),
101+
SizedBox(height: 30,),
102+
VerificationCode(
103+
textStyle: TextStyle(fontSize: 20.0, color: Colors.black),
104+
underlineColor: Colors.blueAccent,
105+
keyboardType: TextInputType.number,
106+
length: 6,
107+
onCompleted: (String value) {
108+
setState(() {
109+
_code = value;
110+
});
111+
},
112+
onEditing: (bool value) {
113+
setState(() {
114+
_onEditing = value;
115+
});
116+
},
117+
),
118+
SizedBox(height: 20,),
119+
Row(
120+
mainAxisAlignment: MainAxisAlignment.center,
121+
children: [
122+
Text("Don't resive the OTP?",
123+
style: TextStyle(fontSize: 14, height: 1.5, color: Colors.grey.shade500),),
124+
TextButton(
125+
onPressed: () {
126+
if (_isResendAgain) return;
127+
startTimer();
128+
},
129+
child: Text(_isResendAgain ? 'Try again in ' + _start.toString() : "Resend",
130+
style: TextStyle(fontSize: 14, height: 1.5, color: Colors.blueAccent),)
131+
),
132+
],
133+
),
134+
SizedBox(height:50,),
135+
MaterialButton(
136+
disabledColor: Colors.grey.shade300,
137+
height: 50,
138+
onPressed: _code.length < 6 ? null : () { verify(); },
139+
minWidth: double.infinity,
140+
color: Colors.black,
141+
shape: RoundedRectangleBorder(
142+
borderRadius: BorderRadius.circular(5)
143+
),
144+
child: _isLoading ? Container(
145+
width: 20,
146+
height: 20,
147+
child: CircularProgressIndicator(
148+
backgroundColor: Colors.white,
149+
strokeWidth: 3,
150+
color: Colors.black,
151+
),
152+
) : _isVerified ? Icon(Icons.check_circle, color: Colors.white, size: 30,) : Text("Verify", style: TextStyle(color: Colors.white),),
153+
),
154+
],
155+
),
156+
),
157+
),
158+
);
159+
}
160+
}

pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626

27+
flutter_verification_code: ^1.0.4
28+
2729

2830
# The following adds the Cupertino Icons font to your application.
2931
# Use with the CupertinoIcons class for iOS style icons.
@@ -45,7 +47,8 @@ flutter:
4547
uses-material-design: true
4648

4749
# To add assets to your application, add an assets section, like this:
48-
# assets:
50+
assets:
51+
- assets/
4952
# - images/a_dot_burr.jpeg
5053
# - images/a_dot_ham.jpeg
5154

0 commit comments

Comments
 (0)