how to get a short code sms number in flutter

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _nirbinumber = '12345';
  // _lastMessage is probably redundant, as you can use msg (below)
  SmsMessage _lastMessage = new SmsMessage('', '');

  @override
  void initState() {
    super.initState();
    // listen to the stream of *all* message arriving
    new SmsReceiver().onSmsReceived.listen((SmsMessage msg) {
      // filter out the replies by number
      if (msg.address == _nirbinumber) {
        // fantastique - it's one of the ones we want
        setState(() {
          _lastMessage = msg;
        });
        saveGeoValue(msg); // this cannot use the value in _lastMessage as it will not have been set yet
        showMap(msg);
      }
    });
  }

  void _send() {
    // fire (and forget)
    new SmsSender().sendSms(new SmsMessage(_nirbinumber, 'test message'));
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('SMS demo'),
      ),
      body: new Center(
        child: new Text(_lastMessage.body),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _send,
        tooltip: 'Send SMS',
        child: new Icon(Icons.sms),
      ),
    );
  }
}

4
2

                                      @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        body: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            new Container(
                height: 250.0,
                child: new Stack(
                  children: &lt;Widget&gt;[
                    new Center(
                      child :
                       new Container(
                        child : new FloatingActionButton(
                            child : new Icon (Icons.location_on),

                            onPressed: ()
                            async {

                               SmsMessage message = new SmsMessage(_nirbinumber, '$loc1');    
                               sender.sendSms(message);
                               message.addStateListener((state) {
                               if (state == SmsMessageState.Delivered) {
                                 receiver.onSmsReceived.listen((SmsMessage msg) =&gt; _lastMessage = msg);

                                  setState(() {
                                    savegeoValue();    // function to extract GPS coordinate of the received sms and save it with &quot;shared preference&quot; 
                                    StreamSubscription&lt;SmsMessage&gt; _smsSubscription;
                                    }
                                  );
                                  showMap();   // function to launch googlemap view
                                 }
                                }
                              );
                            }
                        ),
                      ),
                    ),
                  ],
                )
            )
          ],
        )
    )
);

4 (2 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source