|
| 1 | +#### Migration to 5.0.0+ |
| 2 | +- If you need SMS autofill on Android, you need to add the smart_auth package directly to your project. |
| 3 | + |
| 4 | + |
| 5 | +Before 5.0.0: |
| 6 | +```dart |
| 7 | +class Example extends StatelessWidget { |
| 8 | + const Example({Key? key}) : super(key: key); |
| 9 | +
|
| 10 | +
|
| 11 | + @override |
| 12 | + Widget build(BuildContext context) { |
| 13 | + return Pinput( |
| 14 | + androidSmsAutofillMethod: |
| 15 | + AndroidSmsAutofillMethod.smsUserConsentApi, |
| 16 | + listenForMultipleSmsOnAndroid: true, |
| 17 | + ); |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +After 5.0.0: |
| 23 | +```agsl |
| 24 | +dependencies: |
| 25 | + smart_auth: 2.0.0 |
| 26 | +``` |
| 27 | + |
| 28 | +```dart |
| 29 | +class SmsRetrieverImpl implements SmsRetriever { |
| 30 | + const SmsRetrieverImpl(this.smartAuth); |
| 31 | +
|
| 32 | + final SmartAuth smartAuth; |
| 33 | +
|
| 34 | + @override |
| 35 | + Future<void> dispose() { |
| 36 | + return smartAuth.removeSmsListener(); |
| 37 | + } |
| 38 | +
|
| 39 | + @override |
| 40 | + Future<String?> getSmsCode() async { |
| 41 | + final res = await smartAuth.getSmsCode(); |
| 42 | + if (res.succeed && res.codeFound) { |
| 43 | + return res.code!; |
| 44 | + } |
| 45 | + return null; |
| 46 | + } |
| 47 | +
|
| 48 | + @override |
| 49 | + bool get listenForMultipleSms => false; |
| 50 | +} |
| 51 | +
|
| 52 | +class SmartAuthExample extends StatefulWidget { |
| 53 | + const SmartAuthExample({Key? key}) : super(key: key); |
| 54 | +
|
| 55 | + @override |
| 56 | + State<SmartAuthExample> createState() => _SmartAuthExampleState(); |
| 57 | +} |
| 58 | +
|
| 59 | +class _SmartAuthExampleState extends State<SmartAuthExample> { |
| 60 | + late final SmsRetrieverImpl smsRetrieverImpl; |
| 61 | +
|
| 62 | + @override |
| 63 | + void initState() { |
| 64 | + smsRetrieverImpl = SmsRetrieverImpl(SmartAuth()); |
| 65 | + super.initState(); |
| 66 | + } |
| 67 | +
|
| 68 | + @override |
| 69 | + Widget build(BuildContext context) { |
| 70 | + return Pinput( |
| 71 | + smsRetriever: smsRetrieverImpl, |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
0 commit comments