-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_otp_phone_input_widget.dart
68 lines (62 loc) · 2.1 KB
/
2_otp_phone_input_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'package:firebase_multi_factor_auth/firebase_multi_factor_auth.dart';
import 'package:flutter/material.dart';
class OTPPhoneWidget extends StatefulWidget {
const OTPPhoneWidget({Key? key}) : super(key: key);
@override
_OTPPhoneWidgetState createState() => _OTPPhoneWidgetState();
}
class _OTPPhoneWidgetState extends State<OTPPhoneWidget> {
final phoneController = TextEditingController();
final formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
key: formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextFormField(
keyboardType: TextInputType.phone,
controller: phoneController,
autofocus: true,
onFieldSubmitted: (value) {
if (formKey.currentState!.validate()) {
FirebaseMultiFactorAuth.inputPhoneNumberSendOTP(
context: context, phoneNumber: phoneController.text);
}
},
decoration: const InputDecoration(
helperText: "Use the format +49 123 456789 or 0049 123 456789",
hintText: "+49 123 1234567",
),
validator: (value) => (value != null && value.isNotEmpty)
? null
: "Number can't be empty.",
),
const SizedBox(
height: 16,
),
TextButton(
child: const Text("SEND"),
onPressed: () {
if (formKey.currentState!.validate()) {
FirebaseMultiFactorAuth.inputPhoneNumberSendOTP(
context: context, phoneNumber: phoneController.text);
}
},
),
],
),
),
);
}
@override
void dispose() {
phoneController.dispose();
super.dispose();
}
}