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),
),
);
}
}