Skip to content

Commit

Permalink
Chore: removed unnecessary type declarations, Clean up (#38)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Tkko authored Jan 1, 2025
1 parent e3229f4 commit 7fd847b
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 70 deletions.
4 changes: 3 additions & 1 deletion .github/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"subosito",
"reinitializing",
"buildscript",
"Xeor"
"Xeor",
"Dishank",
"Jindal"
]
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#### 3.2.0 · 1/1/2025

- Fixed method type
by [Dishank Jindal](https://github.com/dishankjindal1) - [PR](https://github.com/Tkko/flutter_smart_auth/pull/37)
- Removed unnecessary type declarations
- Removed unnecessary `exclude` from the `analyses_options.yaml`
- Replaced `flutter_lints` with `very_good_analysis` in the example app

#### 3.1.0 · 22/12/2024

- Lowered Java version to 11 for better compatibility
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void getSmsWithUserConsentApi() async {
if (res.hasData) {
final code = res.requireData.code;
/// The code can be null if the SMS is received but the code is extracted from it
/// The code can be null if the SMS was received but the code was not extracted from it
if (code == null) return;
// Use the code
} else if (res.isCanceled) {
Expand Down Expand Up @@ -214,7 +214,7 @@ void getSmsWithRetrieverApi() async {
if (res.hasData) {
final code = res.requireData.code;
/// The code can be null if the SMS is received but the code is extracted from it
/// The code can be null if the SMS was received but the code was not extracted from it
if (code == null) return;
// Use the code
} else {
Expand Down
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ analyzer:
missing_required_param: warning
missing_return: warning
todo: ignore
exclude:
- flutter/**
- lib/api/*.dart

linter:
rules:
Expand Down
8 changes: 2 additions & 6 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: ../analysis_options.yaml
include: package:very_good_analysis/analysis_options.yaml

linter:
# The lint rules applied to this project can be customized in the
Expand All @@ -13,8 +13,4 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
cascade_invocations: false
22 changes: 15 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ void main() {
runApp(const MyApp());
}

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

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

@override
void dispose() {
/// Removes the listeners if the SMS code is not received yet
smartAuth.removeSmsRetrieverApiListener();

/// Removes the listeners if the SMS code is not received yet
smartAuth.removeUserConsentApiListener();

pinputController.dispose();
super.dispose();
}

void getAppSignature() async {
Future<void> getAppSignature() async {
final res = await smartAuth.getAppSignature();
setState(() => appSignature = res.data);
debugPrint('Signature: $res');
}

void userConsent() async {
Future<void> userConsent() async {
final res = await smartAuth.getSmsWithUserConsentApi();
if (res.hasData) {
debugPrint('userConsent: $res');
final code = res.requireData.code;

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

void smsRetriever() async {
Future<void> smsRetriever() async {
final res = await smartAuth.getSmsWithRetrieverApi();
if (res.hasData) {
debugPrint('smsRetriever: $res');
final code = res.requireData.code;

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

void requestPhoneNumberHint() async {
Future<void> requestPhoneNumberHint() async {
final res = await smartAuth.requestPhoneNumberHint();
if (res.hasData) {
// Use the phone number
Expand Down Expand Up @@ -101,7 +109,7 @@ class _MyAppState extends State<MyApp> {
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: TextField(
controller: pinputController,
decoration: const InputDecoration(
Expand Down
28 changes: 10 additions & 18 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "5.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -104,14 +96,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "4a16b3f03741e1252fda5de3ce712666d010ba2122f8e912c94f9f7b90e1a4c3"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -155,7 +139,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.1.0"
version: "3.2.0"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -212,6 +196,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
very_good_analysis:
dependency: "direct dev"
description:
name: very_good_analysis
sha256: "62d2b86d183fb81b2edc22913d9f155d26eb5cf3855173adb1f59fac85035c63"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
vm_service:
dependency: transitive
description:
Expand All @@ -221,5 +213,5 @@ packages:
source: hosted
version: "14.3.0"
sdks:
dart: ">=3.6.0-0 <4.0.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
8 changes: 4 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ environment:
dependencies:
flutter:
sdk: flutter

smart_auth:
path: ../
flutter_localizations:
sdk: flutter
smart_auth:
path: ../


dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
very_good_analysis: ^7.0.0


flutter:
Expand Down
22 changes: 8 additions & 14 deletions lib/src/models/smart_auth_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@ enum SmartAuthResultState {

/// The result returned from SmartAuth methods
class SmartAuthResult<T> {
const SmartAuthResult({
required this.state,
required this.data,
required this.error,
});

const SmartAuthResult.success(this.data)
: state = SmartAuthResultState.success,
: _state = SmartAuthResultState.success,
error = null;

const SmartAuthResult.failure(this.error)
: state = SmartAuthResultState.failure,
: _state = SmartAuthResultState.failure,
data = null;

const SmartAuthResult.canceled()
: state = SmartAuthResultState.canceled,
: _state = SmartAuthResultState.canceled,
error = null,
data = null;

/// The state of the result
final SmartAuthResultState state;
final SmartAuthResultState _state;

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

/// Returns whether user canceled the operation.
bool get isCanceled => state == SmartAuthResultState.canceled;
bool get isCanceled => _state == SmartAuthResultState.canceled;

@override
String toString() {
return 'SmartAuthResult{state: $state, data: $data, error: $error}';
return 'SmartAuthResult{state: $_state, data: $data, error: $error}';
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SmartAuthResult &&
runtimeType == other.runtimeType &&
state == other.state &&
_state == other._state &&
data == other.data &&
error == other.error;

@override
int get hashCode => state.hashCode ^ data.hashCode ^ error.hashCode;
int get hashCode => _state.hashCode ^ data.hashCode ^ error.hashCode;
}
28 changes: 14 additions & 14 deletions lib/src/smart_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SmartAuth {
Future<SmartAuthResult<String>> getAppSignature() async {
try {
final result = await _api.getAppSignature();
return SmartAuthResult<String>.success(result);
return SmartAuthResult.success(result);
} catch (error) {
debugPrint('Pinput/SmartAuth: getAppSignature failed: $error');
return SmartAuthResult.failure(
Expand All @@ -55,12 +55,12 @@ class SmartAuth {
}) async {
try {
final result = await _api.getSmsWithRetrieverApi();
return SmartAuthResult<SmartAuthSms>.success(
return SmartAuthResult.success(
SmartAuthSms.fromSms(result, matcher),
);
} catch (error) {
debugPrint('Pinput/SmartAuth: getSmsWithRetrieverApi failed: $error');
return SmartAuthResult<SmartAuthSms>.failure(
return SmartAuthResult.failure(
'Failed to get SMS with retriever API with error: $error',
);
}
Expand All @@ -78,7 +78,7 @@ class SmartAuth {
}) async {
try {
final result = await _api.getSmsWithUserConsentApi(senderPhoneNumber);
return SmartAuthResult<SmartAuthSms>.success(
return SmartAuthResult.success(
SmartAuthSms.fromSms(result, matcher),
);
} catch (error) {
Expand All @@ -87,10 +87,10 @@ class SmartAuth {

if (isCanceled) {
debugPrint('Pinput/SmartAuth: ${error.message}');
return SmartAuthResult<SmartAuthSms>.canceled();
return SmartAuthResult.canceled();
}
debugPrint('Pinput/SmartAuth: getSmsWithUserConsentApi failed: $error');
return SmartAuthResult<SmartAuthSms>.failure(
return SmartAuthResult.failure(
'Failed to get SMS with user consent API with error: $error',
);
}
Expand All @@ -100,10 +100,10 @@ class SmartAuth {
Future<SmartAuthResult<void>> removeUserConsentApiListener() async {
try {
await _api.removeUserConsentListener();
return SmartAuthResult<void>.success(null);
return SmartAuthResult.success(null);
} catch (error) {
debugPrint('Pinput/SmartAuth: removeUserConsentListener failed: $error');
return SmartAuthResult<void>.failure(
return SmartAuthResult.failure(
'Failed to remove user consent listener with error: $error',
);
}
Expand All @@ -113,10 +113,10 @@ class SmartAuth {
Future<SmartAuthResult<void>> removeSmsRetrieverApiListener() async {
try {
await _api.removeSmsRetrieverListener();
return SmartAuthResult<void>.success(null);
return SmartAuthResult.success(null);
} catch (error) {
debugPrint('Pinput/SmartAuth: removeSmsRetrieverListener failed: $error');
return SmartAuthResult<void>.failure(
return SmartAuthResult.failure(
'Failed to remove sms retriever listener with error: $error',
);
}
Expand All @@ -125,21 +125,21 @@ class SmartAuth {
/// Runs the Phone Number Hint API, a library powered by Google Play services
/// provides a frictionless way to show a user’s (SIM-based) phone numbers as a hint.
/// https://developers.google.com/identity/phone-number-hint/android
Future<SmartAuthResult<String?>> requestPhoneNumberHint() async {
Future<SmartAuthResult<String>> requestPhoneNumberHint() async {
try {
final result = await _api.requestPhoneNumberHint();
return SmartAuthResult<String?>.success(result);
return SmartAuthResult.success(result);
} catch (error) {
final isCanceled = error is PlatformException &&
error.details is SmartAuthRequestCanceled;
if (isCanceled) {
debugPrint('Pinput/SmartAuth: requestPhoneNumberHint canceled by user');
return SmartAuthResult<String?>.canceled();
return SmartAuthResult.canceled();
}

final message = 'Failed to request phone number hint with error: $error';
debugPrint('Pinput/SmartAuth: $message');
return SmartAuthResult<String?>.failure(message);
return SmartAuthResult.failure(message);
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: smart_auth
description: Wrapper of Android SMS User Consent API, SMS Retriever API to read one time sms code, get user phone number, OTP, OTC, sms autofill, android autofill
homepage: https://github.com/Tkko/flutter_smart_auth
repository: https://github.com/Tkko/flutter_smart_auth
version: 3.1.0
version: 3.2.0
topics:
- otp
- sms-autofill
Expand Down

0 comments on commit 7fd847b

Please sign in to comment.