How to open Dialog when user tabs the push notification messages

892 views
Skip to first unread message

Niyazi Toros

unread,
Jun 22, 2018, 2:32:05 AM6/22/18
to Flutter Dev
Hi,

I build a demo app using the "firebase_messaging: "0.2.1"". what I need is that how to catch messages in app?
I can send the firebase push notification and receive it. But when I tab the message it opens my app and doesnt shows anything. I have very basic design to open the app and dialog box but I don't get anything to show to user.

How to open Dialog when user tabs the push notification messages?


The CODE:

@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);
}
Reply all
Reply to author
Forward
0 new messages