how to get a short code sms number in flutter code example
Example 1: 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';
SmsMessage _lastMessage = new SmsMessage('', '');
@override
void initState() {
super.initState();
new SmsReceiver().onSmsReceived.listen((SmsMessage msg) {
if (msg.address == _nirbinumber) {
setState(() {
_lastMessage = msg;
});
saveGeoValue(msg);
showMap(msg);
}
});
}
void _send() {
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),
),
);
}
}
Example 2: how to get a short code sms number in flutter
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
height: 250.0,
child: new Stack(
children: <Widget>[
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) => _lastMessage = msg);
setState(() {
savegeoValue();
StreamSubscription<SmsMessage> _smsSubscription;
}
);
showMap();
}
}
);
}
),
),
),
],
)
)
],
)
)
);