email_otp 1.0.0 email_otp: ^1.0.0 copied to clipboard
A fast & simple email authentication OTP sender and verification flutter package.
Here the example of all method, enjoy coding 😃
import 'package:email_otp/email_otp.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController email = new TextEditingController();
TextEditingController otp = new TextEditingController();
Email_OTP myauth = Email_OTP();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: email,
decoration:
const InputDecoration(hintText: "User Email")),
),
ElevatedButton(
onPressed: () async {
myauth.setConfig(
appEmail: "me@rohitchouhan.com",
appName: "Email OTP",
userEmail: email.text,
);
if (await myauth.sendOTP() == true) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("OTP has been sent"),
));
} else {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("Oops, OTP send failed"),
));
}
},
child: const Text("Send OTP")),
],
),
),
Card(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: otp,
decoration:
const InputDecoration(hintText: "Enter OTP")),
),
ElevatedButton(
onPressed: () async {
if (await myauth.verifyOTP(otp: otp.text) == true) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("OTP is verified"),
));
} else {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text("Invalid OTP"),
));
}
},
child: const Text("Verify")),
],
),
)
],
),
),
),
);
}
}