-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_otp_controller_widget.dart
50 lines (43 loc) · 1.89 KB
/
3_otp_controller_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
import 'package:firebase_multi_factor_auth/provider/otp_provider.dart';
import 'package:firebase_multi_factor_auth/provider/user_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../provider/auth_provider.dart';
import '../utils/logger.dart';
/// This widget is used to control the flow of the One-Time-Passcode (OTP) flow.
/// [phoneInputWidget] is the widget that is shown when the user may enter their phone number.
/// [firstLoginWidget] is the widget that is shown when the user is logging in for the first time.
/// [otpSentWidget] is the widget that is shown when the OTP is sent to the user's phone.
///
/// The [OTPProvider] is a [ChangeNotifier] that is used to notify the [OTPControllerWidget]
class OTPControllerWidget extends StatelessWidget {
const OTPControllerWidget(
{super.key,
required this.otpSentWidget,
required this.firstLoginWidget,
required this.phoneInputWidget});
final Widget otpSentWidget, firstLoginWidget, phoneInputWidget;
@override
Widget build(BuildContext context) {
return Consumer<OTPProvider>(
builder: (context, value, child) => buildOnStateChange(context, value));
}
Widget buildOnStateChange(BuildContext context, OTPProvider otpProvider) {
if (otpProvider.otpState == OTPState.OTP_SENT) {
return otpSentWidget;
} else if (otpProvider.otpState == OTPState.FIRST_LOGIN) {
var userProvider = Provider.of<UserProvider>(context, listen: false);
if (userProvider.userFetched != null) {
if (userProvider.userFetched!.firstLogin) {
return firstLoginWidget;
} else {
logger.d("2 Factor Authenticated!!! TWO FACTOR 2fa");
Provider.of<AuthProvider>(context, listen: false)
.is2FactorAuthenticated = true;
}
}
}
return phoneInputWidget;
}
}