-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotp_provider.dart
57 lines (44 loc) · 1.21 KB
/
otp_provider.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
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import '../utils/logger.dart';
/// Missing field check is for checking username, phone and etc.
/// First asking for phone number
/// Then asking for otp code
/// Then missing field check.
enum OTPState { PHONE_INPUT, OTP_SENT, FIRST_LOGIN }
class OTPProvider extends ChangeNotifier {
OTPState _otpState = OTPState.PHONE_INPUT;
/* Changes recognized */
String? phoneNumber;
ConfirmationResult? confirmationResult;
bool _disposed = false;
// mobile
String? verificationID;
OTPState get otpState => _otpState;
set otpState(OTPState state) {
if (state == _otpState) return;
_otpState = state;
notifyListeners();
}
/// Sign this provider out and erase its data with this function
void reset() {
_disposed = true;
phoneNumber = null;
verificationID = null;
confirmationResult = null;
otpState = OTPState.PHONE_INPUT;
_disposed = false;
logger.i("[OTPProvider] Should be signed out!");
}
@override
void dispose() {
_disposed = true;
super.dispose();
}
@override
void notifyListeners() {
if (!_disposed) {
super.notifyListeners();
}
}
}