@override
void initState() {
// TODO: implement initState
super.initState();
connectivity = new Connectivity();
subscription =
connectivity.onConnectivityChanged.listen((ConnectivityResult result) {
_connectionStatus = result.toString();
//print(_connectionStatus);
if (result == ConnectivityResult.wifi ||
result == ConnectivityResult.mobile) {
setState(() {
appLive = 1;
// TODO: PUSH NOTIFICATION *******************************************
if (appLive == 1) {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
print('onMessage: $message');
_showDialog(message);
},
onResume: (Map<String, dynamic> message) {
print('onResume: $message');
_showDialog(message);
},
onLaunch: (Map<String, dynamic> message) {
print('onLaunch: $message');
_showDialog(message);
},
);
_firebaseMessaging.getToken().then((token) {
print(token);
});
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Setings resgistred: $settings");
});
}
// TODO: PUSH NOTIFICATION *******************************************
});
} else {
setState(() {
appLive = 0;
});
}
// print(appLive);
// print(_connectionStatus);
});
}
void _showDialog(value) {
AlertDialog alertDialog = new AlertDialog(
content: new Container(
height: 400.0,
child: new Column(
children: <Widget>[
new Text(
"MyCompany:",
),
new Text(
"$value",
),
new Padding(padding: EdgeInsets.all(20.0)),
new RaisedButton(
child: new Text("OK"),
onPressed: () => Navigator.pop(context),
)
],
),
),
);
showDialog(context: context, child: alertDialog);
}