otp_consent 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new63

otp_consent #

Flutter plugin to provide SMS User Consent API gives the content of a single SMS message to us if the user gives permission. For Android, that's where this package is useful. No need for iOS

Example app

Getting Started #

SMS need to follow some rules as describe here

  • Contains one-time code
  • 4-10 digit alphanumeric with one number
  • Not from contact

Usage #

import 'import package:otp_consent/otp_consent.dart';

Extend OtpConsentAutoFill mixin that will offer you:

  • startSmsListening(): to listen SMS code from the native
  • stopSmsListen(): to stop listen broadcast receiver from native
  • smsReceived(sms): call get value otp when the sms is received.
  • sms: get sms code received

0.0.1 #

  • Initial release.

1.0.0 #

  • Release.

1.0.1 #

  • Update doc.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:otp_consent/otp_consent.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with OtpConsentAutoFill {
  var otpConsent = OtpConsent();
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await otpConsent.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin otp consent example app'),
        ),
        body: Container(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Text('Running on: $_platformVersion'),
                MaterialButton(
                  color: Colors.red,
                  textColor: Colors.white,
                  child: Text('Start Listening'),
                  onPressed: () async {
                    startSmsListening();
                  },
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  void smsReceived(String sms) {
    print(sms);
  }

  @override
  void dispose() {
    stopSmsListen();
    super.dispose();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  otp_consent: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:otp_consent/otp_consent.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:otp_consent/otp_consent.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:otp_consent/otp_consent.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:otp_consent/otp_consent.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:otp_consent/otp_consent.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • otp_consent that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test