get_sms_otp_consent 0.0.3+3 copy "get_sms_otp_consent: ^0.0.3+3" to clipboard
get_sms_otp_consent: ^0.0.3+3 copied to clipboard

PlatformAndroid

A Flutter plugin to provide SMS code auto-retrieval and device's phone number extraction

get_sms_otp_consent #

Flutter plugin to provide SMS code autofill support.

If you want to avoid including any 11-character hash strings in your SMS messages, this plugin can help. While iOS offers SMS autofill functionality natively, Android requires this package to achieve the same behavior. SmsConsentAPI automatically requests permission to read the otp code.

How to install #

Android #

SMS User Consent API rules for SMS messages: The message must contain a 4-10 character alphanumeric code with at least one number and be sent from a phone number not saved in the user's contacts.

android {
  ...
  defaultConfig {
    ...
    minSdkVersion 21
    ...
  }
  ...
}

Getting Started #

dependencies:
  get_sms_otp_consent: <latest version>

To use the latest changes:

  get_sms_otp_consent:
    git:
      url: https://github.com/Tughra/SmsConsentFlutterPlugin.git
      ref: master

Usage #

Import this class

import 'package:get_sms_otp_consent/get_sms_otp_consent.dart';
class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String? _receivedSms ;
  String? _phoneNumber ;
  final _smsConsentPlugin = GetSmsOtpConsent();
  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SMS Consent Example'),
        ),
        body: Center(
          child: Column(
            children: [
              TextButton(onPressed: ()async{
                //_launchCustomActivity();
                _phoneNumber= await _smsConsentPlugin.getPhoneNumber();
                setState(() {

                });
              }, child: const Text("Get Phone Number")),
              TextButton(onPressed: ()async{
                //_launchCustomActivity();
                await _smsConsentPlugin.initializeSmsConsent("OtpSMS");
                _receivedSms = await _smsConsentPlugin.getOtpSmsMessage();
                setState(() {

                });
              }, child: const Text("Listen Otp")),
              TextButton(onPressed: (){
                //_disposeActivity();
                _smsConsentPlugin.disposeSmsConsent();
              }, child: const Text("Dispose ListenOtp")),
              if(_receivedSms!=null)Text(_receivedSms!),
              if(_phoneNumber!=null)Text(_phoneNumber!)
            ],
          ),
        ),
      ),
    );
  }
}

When you initialized the "initializeSmsConsent", the method's String parameter (_smsConsentPlugin.initializeSmsConsent("OtpSMS")) has to be same with received Sms Message's sender name.

1
likes
140
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to provide SMS code auto-retrieval and device's phone number extraction

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on get_sms_otp_consent

Packages that implement get_sms_otp_consent