Skip to content

Commit 7fd847b

Browse files
authored
Chore: removed unnecessary type declarations, Clean up (#38)
* Replaced flutter_lints with very_good_analysis in the example app * Removed unnecessary type declarations * Fixed readme comments * Removed unnecessary exclude * Version 3.2.0 * Fixed grammar * spell check ignore word - Jindal * Fixed typo * Fixed typo
1 parent e3229f4 commit 7fd847b

File tree

11 files changed

+67
-70
lines changed

11 files changed

+67
-70
lines changed

.github/cspell.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"subosito",
3232
"reinitializing",
3333
"buildscript",
34-
"Xeor"
34+
"Xeor",
35+
"Dishank",
36+
"Jindal"
3537
]
3638
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#### 3.2.0 · 1/1/2025
2+
3+
- Fixed method type
4+
by [Dishank Jindal](https://github.com/dishankjindal1) - [PR](https://github.com/Tkko/flutter_smart_auth/pull/37)
5+
- Removed unnecessary type declarations
6+
- Removed unnecessary `exclude` from the `analyses_options.yaml`
7+
- Replaced `flutter_lints` with `very_good_analysis` in the example app
8+
19
#### 3.1.0 · 22/12/2024
210

311
- Lowered Java version to 11 for better compatibility

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void getSmsWithUserConsentApi() async {
169169
if (res.hasData) {
170170
final code = res.requireData.code;
171171
172-
/// The code can be null if the SMS is received but the code is extracted from it
172+
/// The code can be null if the SMS was received but the code was not extracted from it
173173
if (code == null) return;
174174
// Use the code
175175
} else if (res.isCanceled) {
@@ -214,7 +214,7 @@ void getSmsWithRetrieverApi() async {
214214
if (res.hasData) {
215215
final code = res.requireData.code;
216216
217-
/// The code can be null if the SMS is received but the code is extracted from it
217+
/// The code can be null if the SMS was received but the code was not extracted from it
218218
if (code == null) return;
219219
// Use the code
220220
} else {

analysis_options.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ analyzer:
55
missing_required_param: warning
66
missing_return: warning
77
todo: ignore
8-
exclude:
9-
- flutter/**
10-
- lib/api/*.dart
118

129
linter:
1310
rules:

example/analysis_options.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: ../analysis_options.yaml
1+
include: package:very_good_analysis/analysis_options.yaml
22

33
linter:
44
# The lint rules applied to this project can be customized in the
@@ -13,8 +13,4 @@ linter:
1313
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
1414
# producing the lint.
1515
rules:
16-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
17-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
18-
19-
# Additional information about this file can be found at
20-
# https://dart.dev/guides/language/analysis-options
16+
cascade_invocations: false

example/lib/main.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ void main() {
66
runApp(const MyApp());
77
}
88

9+
/// This example demonstrates how to use the SmartAuth plugin.
910
class MyApp extends StatefulWidget {
11+
/// Creates a new instance of the [MyApp] class.
1012
const MyApp({Key? key}) : super(key: key);
1113

1214
@override
@@ -20,25 +22,30 @@ class _MyAppState extends State<MyApp> {
2022

2123
@override
2224
void dispose() {
25+
/// Removes the listeners if the SMS code is not received yet
2326
smartAuth.removeSmsRetrieverApiListener();
27+
28+
/// Removes the listeners if the SMS code is not received yet
2429
smartAuth.removeUserConsentApiListener();
30+
2531
pinputController.dispose();
2632
super.dispose();
2733
}
2834

29-
void getAppSignature() async {
35+
Future<void> getAppSignature() async {
3036
final res = await smartAuth.getAppSignature();
3137
setState(() => appSignature = res.data);
3238
debugPrint('Signature: $res');
3339
}
3440

35-
void userConsent() async {
41+
Future<void> userConsent() async {
3642
final res = await smartAuth.getSmsWithUserConsentApi();
3743
if (res.hasData) {
3844
debugPrint('userConsent: $res');
3945
final code = res.requireData.code;
4046

41-
/// The code can be null if the SMS is received but the code is extracted from it
47+
/// The code can be null if the SMS was received but
48+
/// the code was not extracted from it
4249
if (code == null) return;
4350
pinputController.text = code;
4451
pinputController.selection = TextSelection.fromPosition(
@@ -51,13 +58,14 @@ class _MyAppState extends State<MyApp> {
5158
}
5259
}
5360

54-
void smsRetriever() async {
61+
Future<void> smsRetriever() async {
5562
final res = await smartAuth.getSmsWithRetrieverApi();
5663
if (res.hasData) {
5764
debugPrint('smsRetriever: $res');
5865
final code = res.requireData.code;
5966

60-
/// The code can be null if the SMS is received but the code is extracted from it
67+
/// The code can be null if the SMS was received but
68+
/// the code was not extracted from it
6169
if (code == null) return;
6270
pinputController.text = code;
6371
pinputController.selection = TextSelection.fromPosition(
@@ -68,7 +76,7 @@ class _MyAppState extends State<MyApp> {
6876
}
6977
}
7078

71-
void requestPhoneNumberHint() async {
79+
Future<void> requestPhoneNumberHint() async {
7280
final res = await smartAuth.requestPhoneNumberHint();
7381
if (res.hasData) {
7482
// Use the phone number
@@ -101,7 +109,7 @@ class _MyAppState extends State<MyApp> {
101109
mainAxisSize: MainAxisSize.min,
102110
children: [
103111
Padding(
104-
padding: const EdgeInsets.all(8.0),
112+
padding: const EdgeInsets.all(8),
105113
child: TextField(
106114
controller: pinputController,
107115
decoration: const InputDecoration(

example/pubspec.lock

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ packages:
5454
description: flutter
5555
source: sdk
5656
version: "0.0.0"
57-
flutter_lints:
58-
dependency: "direct dev"
59-
description:
60-
name: flutter_lints
61-
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
62-
url: "https://pub.dev"
63-
source: hosted
64-
version: "5.0.0"
6557
flutter_localizations:
6658
dependency: "direct main"
6759
description: flutter
@@ -104,14 +96,6 @@ packages:
10496
url: "https://pub.dev"
10597
source: hosted
10698
version: "3.0.1"
107-
lints:
108-
dependency: transitive
109-
description:
110-
name: lints
111-
sha256: "4a16b3f03741e1252fda5de3ce712666d010ba2122f8e912c94f9f7b90e1a4c3"
112-
url: "https://pub.dev"
113-
source: hosted
114-
version: "5.1.0"
11599
matcher:
116100
dependency: transitive
117101
description:
@@ -155,7 +139,7 @@ packages:
155139
path: ".."
156140
relative: true
157141
source: path
158-
version: "3.1.0"
142+
version: "3.2.0"
159143
source_span:
160144
dependency: transitive
161145
description:
@@ -212,6 +196,14 @@ packages:
212196
url: "https://pub.dev"
213197
source: hosted
214198
version: "2.1.4"
199+
very_good_analysis:
200+
dependency: "direct dev"
201+
description:
202+
name: very_good_analysis
203+
sha256: "62d2b86d183fb81b2edc22913d9f155d26eb5cf3855173adb1f59fac85035c63"
204+
url: "https://pub.dev"
205+
source: hosted
206+
version: "7.0.0"
215207
vm_service:
216208
dependency: transitive
217209
description:
@@ -221,5 +213,5 @@ packages:
221213
source: hosted
222214
version: "14.3.0"
223215
sdks:
224-
dart: ">=3.6.0-0 <4.0.0"
216+
dart: ">=3.5.0 <4.0.0"
225217
flutter: ">=3.18.0-18.0.pre.54"

example/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ environment:
88
dependencies:
99
flutter:
1010
sdk: flutter
11-
12-
smart_auth:
13-
path: ../
1411
flutter_localizations:
1512
sdk: flutter
13+
smart_auth:
14+
path: ../
15+
1616

1717
dev_dependencies:
1818
flutter_test:
1919
sdk: flutter
20-
flutter_lints: ^5.0.0
20+
very_good_analysis: ^7.0.0
2121

2222

2323
flutter:

lib/src/models/smart_auth_result.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ enum SmartAuthResultState {
77

88
/// The result returned from SmartAuth methods
99
class SmartAuthResult<T> {
10-
const SmartAuthResult({
11-
required this.state,
12-
required this.data,
13-
required this.error,
14-
});
15-
1610
const SmartAuthResult.success(this.data)
17-
: state = SmartAuthResultState.success,
11+
: _state = SmartAuthResultState.success,
1812
error = null;
1913

2014
const SmartAuthResult.failure(this.error)
21-
: state = SmartAuthResultState.failure,
15+
: _state = SmartAuthResultState.failure,
2216
data = null;
2317

2418
const SmartAuthResult.canceled()
25-
: state = SmartAuthResultState.canceled,
19+
: _state = SmartAuthResultState.canceled,
2620
error = null,
2721
data = null;
2822

2923
/// The state of the result
30-
final SmartAuthResultState state;
24+
final SmartAuthResultState _state;
3125

3226
/// The data object if [state] is [SmartAuthResultState.success]
3327
final T? data;
@@ -56,22 +50,22 @@ class SmartAuthResult<T> {
5650
bool get hasError => error != null;
5751

5852
/// Returns whether user canceled the operation.
59-
bool get isCanceled => state == SmartAuthResultState.canceled;
53+
bool get isCanceled => _state == SmartAuthResultState.canceled;
6054

6155
@override
6256
String toString() {
63-
return 'SmartAuthResult{state: $state, data: $data, error: $error}';
57+
return 'SmartAuthResult{state: $_state, data: $data, error: $error}';
6458
}
6559

6660
@override
6761
bool operator ==(Object other) =>
6862
identical(this, other) ||
6963
other is SmartAuthResult &&
7064
runtimeType == other.runtimeType &&
71-
state == other.state &&
65+
_state == other._state &&
7266
data == other.data &&
7367
error == other.error;
7468

7569
@override
76-
int get hashCode => state.hashCode ^ data.hashCode ^ error.hashCode;
70+
int get hashCode => _state.hashCode ^ data.hashCode ^ error.hashCode;
7771
}

lib/src/smart_auth.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SmartAuth {
3737
Future<SmartAuthResult<String>> getAppSignature() async {
3838
try {
3939
final result = await _api.getAppSignature();
40-
return SmartAuthResult<String>.success(result);
40+
return SmartAuthResult.success(result);
4141
} catch (error) {
4242
debugPrint('Pinput/SmartAuth: getAppSignature failed: $error');
4343
return SmartAuthResult.failure(
@@ -55,12 +55,12 @@ class SmartAuth {
5555
}) async {
5656
try {
5757
final result = await _api.getSmsWithRetrieverApi();
58-
return SmartAuthResult<SmartAuthSms>.success(
58+
return SmartAuthResult.success(
5959
SmartAuthSms.fromSms(result, matcher),
6060
);
6161
} catch (error) {
6262
debugPrint('Pinput/SmartAuth: getSmsWithRetrieverApi failed: $error');
63-
return SmartAuthResult<SmartAuthSms>.failure(
63+
return SmartAuthResult.failure(
6464
'Failed to get SMS with retriever API with error: $error',
6565
);
6666
}
@@ -78,7 +78,7 @@ class SmartAuth {
7878
}) async {
7979
try {
8080
final result = await _api.getSmsWithUserConsentApi(senderPhoneNumber);
81-
return SmartAuthResult<SmartAuthSms>.success(
81+
return SmartAuthResult.success(
8282
SmartAuthSms.fromSms(result, matcher),
8383
);
8484
} catch (error) {
@@ -87,10 +87,10 @@ class SmartAuth {
8787

8888
if (isCanceled) {
8989
debugPrint('Pinput/SmartAuth: ${error.message}');
90-
return SmartAuthResult<SmartAuthSms>.canceled();
90+
return SmartAuthResult.canceled();
9191
}
9292
debugPrint('Pinput/SmartAuth: getSmsWithUserConsentApi failed: $error');
93-
return SmartAuthResult<SmartAuthSms>.failure(
93+
return SmartAuthResult.failure(
9494
'Failed to get SMS with user consent API with error: $error',
9595
);
9696
}
@@ -100,10 +100,10 @@ class SmartAuth {
100100
Future<SmartAuthResult<void>> removeUserConsentApiListener() async {
101101
try {
102102
await _api.removeUserConsentListener();
103-
return SmartAuthResult<void>.success(null);
103+
return SmartAuthResult.success(null);
104104
} catch (error) {
105105
debugPrint('Pinput/SmartAuth: removeUserConsentListener failed: $error');
106-
return SmartAuthResult<void>.failure(
106+
return SmartAuthResult.failure(
107107
'Failed to remove user consent listener with error: $error',
108108
);
109109
}
@@ -113,10 +113,10 @@ class SmartAuth {
113113
Future<SmartAuthResult<void>> removeSmsRetrieverApiListener() async {
114114
try {
115115
await _api.removeSmsRetrieverListener();
116-
return SmartAuthResult<void>.success(null);
116+
return SmartAuthResult.success(null);
117117
} catch (error) {
118118
debugPrint('Pinput/SmartAuth: removeSmsRetrieverListener failed: $error');
119-
return SmartAuthResult<void>.failure(
119+
return SmartAuthResult.failure(
120120
'Failed to remove sms retriever listener with error: $error',
121121
);
122122
}
@@ -125,21 +125,21 @@ class SmartAuth {
125125
/// Runs the Phone Number Hint API, a library powered by Google Play services
126126
/// provides a frictionless way to show a user’s (SIM-based) phone numbers as a hint.
127127
/// https://developers.google.com/identity/phone-number-hint/android
128-
Future<SmartAuthResult<String?>> requestPhoneNumberHint() async {
128+
Future<SmartAuthResult<String>> requestPhoneNumberHint() async {
129129
try {
130130
final result = await _api.requestPhoneNumberHint();
131-
return SmartAuthResult<String?>.success(result);
131+
return SmartAuthResult.success(result);
132132
} catch (error) {
133133
final isCanceled = error is PlatformException &&
134134
error.details is SmartAuthRequestCanceled;
135135
if (isCanceled) {
136136
debugPrint('Pinput/SmartAuth: requestPhoneNumberHint canceled by user');
137-
return SmartAuthResult<String?>.canceled();
137+
return SmartAuthResult.canceled();
138138
}
139139

140140
final message = 'Failed to request phone number hint with error: $error';
141141
debugPrint('Pinput/SmartAuth: $message');
142-
return SmartAuthResult<String?>.failure(message);
142+
return SmartAuthResult.failure(message);
143143
}
144144
}
145145
}

0 commit comments

Comments
 (0)