smshandler 0.0.1 copy "smshandler: ^0.0.1" to clipboard
smshandler: ^0.0.1 copied to clipboard

Programmatic SMS Handler

smshandler #

Programmatic SMS Handler Supports Android

This package developed for send sms programmatically from your flutter app.

It's in development mode and web, ios currently not supported

Read this documentation for configuring this package , an example is also included

Getting Started #

In your flutter project add the dependency


import 'package:smshandler/smshandler.dart';// import the package

static String number = "YOUR NUMBER"; // variable to store the number

static String msgData = "YOUR MESSAGE";// variable to store the message

static int simId = 0;// variable to provide the simId 0 for SIM1 and 1 for SIM2

 Future<void> smsHandler() async {
   
    String smsResponse;
    
    try {
      smsResponse = await Smshandler.sendYourSms(
        number,
        msgData,
        simId
      );
    } on PlatformException {
      smsResponse = 'SMS_FAILED';
    }

    print(smsResponse);
    
    //call your function for send sms

  }


##this plugin is in development mode ,stay tuned for future updates

##Complete example main.dart file

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:smshandler/smshandler.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  static TextEditingValue number;

  static TextEditingValue msgData;

  TextEditingController numberController =
      TextEditingController.fromValue(number);

  TextEditingController dataController =
      TextEditingController.fromValue(msgData);

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> smsHandler() async {
    String smsResponse;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      smsResponse = await Smshandler.sendYourSms(
        numberController.value.text,
        dataController.value.text,
        0
      );
    } on PlatformException {
      smsResponse = 'SMS_FAILED';
    }

    print(smsResponse);
    
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(
                  left: 10.0,
                  right: 10.0,
                  top: 5.0,
                  bottom: 5.0,
                ),
                child: TextField(
                  keyboardType: TextInputType.number,
                  inputFormatters: <TextInputFormatter>[
                    WhitelistingTextInputFormatter.digitsOnly
                  ],
                  style: TextStyle(color: Colors.teal),
                  decoration: InputDecoration(
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(5.0)),
                  ),
                  controller: numberController,
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(
                  left: 10.0,
                  right: 10.0,
                  top: 5.0,
                  bottom: 5.0,
                ),
                child: TextField(
                  style: TextStyle(color: Colors.teal),
                  decoration: InputDecoration(
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(5.0)),
                  ),
                  controller: dataController,
                ),
              ),
              RaisedButton(
                child: Text("SendSMS"),
                onPressed: () {
                  smsHandler();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}


##this also required permission to send sms add it manually ##in your app you can implement the code to request permission


<uses-permission android:name="android.permission.SEND_SMS" />

1
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Programmatic SMS Handler

Homepage

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on smshandler