### Example pubspec.yaml Entry for smart_auth Source: https://pub.dev/packages/smart_auth/install This is an example of how the smart_auth dependency will appear in your pubspec.yaml file after running the add command. It ensures the package is correctly listed for your project. ```yaml dependencies: smart_auth: ^3.2.0 ``` -------------------------------- ### Smart Auth Flutter Plugin Example App Source: https://pub.dev/packages/smart_auth/example This is the main example app demonstrating various functionalities of the Smart Auth plugin. It includes methods to get the app signature, request SMS codes via user consent or retriever API, and request phone number hints. Ensure you handle the lifecycle of listeners by removing them when no longer needed. ```dart import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:smart_auth/smart_auth.dart'; 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 State createState() => _MyAppState(); } class _MyAppState extends State { final smartAuth = SmartAuth.instance; final pinputController = TextEditingController(); String? appSignature; @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(); } Future getAppSignature() async { final res = await smartAuth.getAppSignature(); setState(() => appSignature = res.data); debugPrint('Signature: $res'); } Future 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 was received but /// the code was not extracted from it if (code == null) return; pinputController.text = code; pinputController.selection = TextSelection.fromPosition( TextPosition(offset: pinputController.text.length), ); } else if (res.isCanceled) { debugPrint('userConsent canceled'); } else { debugPrint('userConsent failed: $res'); } } Future 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 was received but /// the code was not extracted from it if (code == null) return; pinputController.text = code; pinputController.selection = TextSelection.fromPosition( TextPosition(offset: pinputController.text.length), ); } else { debugPrint('smsRetriever failed: $res'); } } Future requestPhoneNumberHint() async { final res = await smartAuth.requestPhoneNumberHint(); if (res.hasData) { // Use the phone number } else { // Handle error } debugPrint('requestHint: $res'); } @override Widget build(BuildContext context) { return MaterialApp( locale: const Locale('es', ''), localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('en', ''), Locale('es', ''), ], debugShowCheckedModeBanner: false, home: Scaffold( body: Center( child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ Padding( padding: const EdgeInsets.all(8), child: TextField( controller: pinputController, decoration: const InputDecoration( hintText: 'Code', border: OutlineInputBorder(), ), ), ), TextButton( onPressed: userConsent, child: const Text('Sms User Consent API'), ), TextButton( onPressed: smsRetriever, child: const Text('Sms Retriever API'), ), TextButton( onPressed: getAppSignature, child: const Text('Get App Signature'), ), if (appSignature != null) SelectableText( 'App Signature: $appSignature', textAlign: TextAlign.center, ), TextButton( onPressed: requestPhoneNumberHint, child: const Text('Request Phone Number Hint'), ), ], ), ), ), ), ); } } ``` -------------------------------- ### Get SMS with User Consent Source: https://pub.dev/packages/smart_auth Implement SMS verification by prompting the user to grant access to a single SMS message. The extracted code is then sent to your server for verification. ```dart void getSmsWithUserConsentApi() async { final res = await smartAuth.getSmsWithUserConsentApi(); if (res.hasData) { final code = res.requireData.code; /// 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) { // User canceled the dialog } else { // handle the error } } ``` -------------------------------- ### Get SMS with SMS Retriever API Source: https://pub.dev/packages/smart_auth Perform automatic SMS-based user verification without user interaction or extra permissions. The API listens for an SMS from your server and extracts the verification code. ```dart void getSmsWithRetrieverApi() async { final res = await smartAuth.getSmsWithRetrieverApi(); if (res.hasData) { final code = res.requireData.code; /// 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 { // handle the error } } ``` -------------------------------- ### Create SmartAuth Instance Source: https://pub.dev/packages/smart_auth Instantiate the SmartAuth class to access its methods. This is the first step before using any of the package's features. ```dart final smartAuth = SmartAuth.instance; ``` -------------------------------- ### Set Kotlin and Gradle Plugin Versions (Legacy) Source: https://pub.dev/packages/smart_auth Configure Kotlin and Gradle plugin versions in the `android/build.gradle` file for legacy imperative apply. ```gradle buildscript { ext.kotlin_version = '1.8.0' ...others dependencies { classpath 'com.android.tools.build:gradle:8.3.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } ``` -------------------------------- ### Set Kotlin and Gradle Plugin Versions (Declarative) Source: https://pub.dev/packages/smart_auth Configure Kotlin and Android application plugin versions in the `android/settings.gradle` file for the new declarative plugin approach. ```gradle plugins { id "org.jetbrains.kotlin.android" version "1.8.0" apply false id "com.android.application" version "8.3.2" apply false ...others } ``` -------------------------------- ### Set Java Version Source: https://pub.dev/packages/smart_auth Configure the Java version to 11 for both source and target compatibility in `android/app/build.gradle`. ```gradle compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '11' } ``` -------------------------------- ### Add smart_auth Dependency to Flutter Project Source: https://pub.dev/packages/smart_auth/install Run this command in your terminal to add the smart_auth package to your Flutter project's dependencies. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add smart_auth ``` -------------------------------- ### Import smart_auth Package in Dart Code Source: https://pub.dev/packages/smart_auth/install Use this import statement in your Dart files to access the functionalities provided by the smart_auth package. This makes the package's classes and methods available for use. ```dart import 'package:smart_auth/smart_auth.dart'; ``` -------------------------------- ### Set Gradle Version Source: https://pub.dev/packages/smart_auth Update the Gradle version to 8.4.0 or above by modifying the `distributionUrl` in `android/gradle/wrapper/gradle-wrapper.properties`. ```properties distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip ``` -------------------------------- ### Request Phone Number Hint Source: https://pub.dev/packages/smart_auth Use the Phone Number Hint API to provide a user's SIM-based phone number as a hint. This API requires no additional permissions and simplifies user input. ```dart void requestPhoneNumberHint() async { final res = await smartAuth.requestPhoneNumberHint(); if (res.hasData) { // Use the phone number } else { // Handle error } } ``` -------------------------------- ### Remove SMS Listeners Source: https://pub.dev/packages/smart_auth Manually remove listeners for SMS retrieval APIs if they are not automatically removed after receiving the code. Use `removeUserConsentApiListener` or `removeSmsRetrieverApiListener`. ```dart void removeSmsListener() { smartAuth.removeUserConsentApiListener(); // or smartAuth.removeSmsRetrieverApiListener(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.