-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
sms_retriever_api_example.dart
50 lines (40 loc) · 1.12 KB
/
sms_retriever_api_example.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:flutter/material.dart';
import 'package:pinput/pinput.dart';
import 'package:smart_auth/smart_auth.dart';
class SmsRetrieverImpl implements SmsRetriever {
const SmsRetrieverImpl(this.smartAuth);
final SmartAuth smartAuth;
@override
Future<void> dispose() {
return smartAuth.removeSmsListener();
}
@override
Future<String?> getSmsCode() async {
final res = await smartAuth.getSmsCode();
if (res.succeed && res.codeFound) {
return res.code!;
}
return null;
}
@override
bool get listenForMultipleSms => false;
}
class SmsRetrieverApiExample extends StatefulWidget {
const SmsRetrieverApiExample({Key? key}) : super(key: key);
@override
State<SmsRetrieverApiExample> createState() => _SmsRetrieverApiExampleState();
}
class _SmsRetrieverApiExampleState extends State<SmsRetrieverApiExample> {
late final SmsRetrieverImpl smsRetrieverImpl;
@override
void initState() {
smsRetrieverImpl = SmsRetrieverImpl(SmartAuth());
super.initState();
}
@override
Widget build(BuildContext context) {
return Pinput(
smsRetriever: smsRetrieverImpl,
);
}
}