@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
4
4
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
5
5
import 'package:form_builder_validators/form_builder_validators.dart' ;
6
6
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart' ;
7
- import 'package:alt_sms_autofill/alt_sms_autofill.dart' ;
8
7
import 'package:thingsboard_app/core/auth/login/login_page_background.dart' ;
9
8
import 'package:thingsboard_app/core/context/tb_context.dart' ;
10
9
import 'package:thingsboard_app/core/context/tb_context_widget.dart' ;
@@ -66,8 +65,6 @@ class TwoFactorAuthenticationPage extends TbPageWidget {
66
65
67
66
class _TwoFactorAuthenticationPageState
68
67
extends TbPageState <TwoFactorAuthenticationPage > {
69
- static RegExp smsCodeRegExp = new RegExp (r"(\d{6})" );
70
-
71
68
final _twoFactorAuthFormKey = GlobalKey <FormBuilderState >();
72
69
ValueNotifier <TwoFaProviderType ?> _selectedProvider =
73
70
ValueNotifier <TwoFaProviderType ?>(null );
@@ -80,7 +77,6 @@ class _TwoFactorAuthenticationPageState
80
77
Timer ? _timer;
81
78
Timer ? _tooManyRequestsTimer;
82
79
ValueNotifier <int > _countDownTime = ValueNotifier <int >(0 );
83
- bool _listenForSms = false ;
84
80
85
81
@override
86
82
void initState () {
@@ -101,9 +97,6 @@ class _TwoFactorAuthenticationPageState
101
97
if (this ._selectedProvider.value != TwoFaProviderType .TOTP ) {
102
98
_sendCode ();
103
99
_showResendAction.value = true ;
104
- if (this ._selectedProvider.value == TwoFaProviderType .SMS ) {
105
- _startListenForSmsCode ();
106
- }
107
100
}
108
101
_timer = Timer .periodic (Duration (seconds: 1 ), (timer) {
109
102
_updatedTime ();
@@ -118,7 +111,6 @@ class _TwoFactorAuthenticationPageState
118
111
if (_tooManyRequestsTimer != null ) {
119
112
_tooManyRequestsTimer! .cancel ();
120
113
}
121
- _cancelSmsCodeListen ();
122
114
super .dispose ();
123
115
}
124
116
@@ -378,39 +370,6 @@ class _TwoFactorAuthenticationPageState
378
370
labelText: providerFormData.placeholderFunction (context)));
379
371
}
380
372
381
- Future <void > _startListenForSmsCode () async {
382
- _listenForSms = true ;
383
- _listenForSmsCode ();
384
- }
385
-
386
- Future <void > _listenForSmsCode () async {
387
- String ? comingSms;
388
- try {
389
- comingSms = await AltSmsAutofill ().listenForSms;
390
- } catch (e) {
391
- _listenForSms = false ;
392
- comingSms = null ;
393
- }
394
- if (comingSms != null ) {
395
- RegExpMatch ? match = smsCodeRegExp.firstMatch (comingSms);
396
- if (match != null ) {
397
- String ? codeStr = match.group (1 );
398
- if (codeStr != null ) {
399
- _twoFactorAuthFormKey.currentState
400
- ? .patchValue ({'verificationCode' : codeStr});
401
- }
402
- }
403
- }
404
- if (_listenForSms) {
405
- _listenForSmsCode ();
406
- }
407
- }
408
-
409
- Future <void > _cancelSmsCodeListen () async {
410
- _listenForSms = false ;
411
- AltSmsAutofill ().unregisterListener ();
412
- }
413
-
414
373
Future <void > _sendVerificationCode (BuildContext context) async {
415
374
FocusScope .of (context).unfocus ();
416
375
if (_twoFactorAuthFormKey.currentState? .saveAndValidate () ?? false ) {
@@ -451,7 +410,6 @@ class _TwoFactorAuthenticationPageState
451
410
_prevProvider = type == null ? _selectedProvider.value : null ;
452
411
_selectedProvider.value = type;
453
412
_showResendAction.value = false ;
454
- await _cancelSmsCodeListen ();
455
413
if (type != null ) {
456
414
var providersInfo = tbContext.twoFactorAuthProviders;
457
415
var providerConfig =
@@ -462,9 +420,6 @@ class _TwoFactorAuthenticationPageState
462
420
_showResendAction.value = true ;
463
421
_minVerificationPeriod =
464
422
providerConfig.minVerificationCodeSendPeriod ?? 30 ;
465
- if (type == TwoFaProviderType .SMS ) {
466
- _startListenForSmsCode ();
467
- }
468
423
}
469
424
}
470
425
}
0 commit comments