Am using FCM for push notification on my app in flutter everything works perfectly on click of the notification on my device notification bar it routes me back to the app and shows a dialog with more details of the notification. But when I kill the app and send a push notification which routes me back to the app and instead of showing me the dialog with more details of the notification I get the below error "NoSuchMethodError The method '+' was called on null". Below is my onMessage, onResume, and Onlaunch.
@override
void initState() {
// TODO: implement initState
super.initState();
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
item_id= message['data']['item_id'].toString();
type_id= message['data']['type_id'].toString();
item_title= message['data']['item_title'].toString();
item_description= message['data']['item_description'].toString();
item_thumbnail_name= message['data']['item_thumbnail_name'].toString();
if(type_id=='1' ){
showGeneralDialog(
barrierLabel: "General Information",
barrierDismissible: false,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: Duration(milliseconds: 1200),
context: context,
pageBuilder: (context, anim1, anim2) {
return Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 400,
child: SingleChildScrollView(child:Column(children: [
SizedBox(height: 10,),
Center(child:Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(0),
child:Material(
color: Colors.white,
child:Text("Information!",style:TextStyle(
fontFamily: 'Montserrat', fontSize: 20.0, color: Colors.black,fontWeight: FontWeight.bold)
))),
],))),
Container(
padding: EdgeInsets.all(5),
child:Material(
color: Colors.white,
child:Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(children: [
Image.asset("assets/640x360.png",fit: BoxFit.cover,
height: 180,),
Image.network(item_thumbnail_name),
],),
Center(child:Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_title,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.pink,
fontSize: 15,fontWeight: FontWeight.bold),
))),
Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_description+"...",
maxLines: 4,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.grey,
fontSize: 12,fontWeight: FontWeight.normal),
)),
],))),
Container(
padding: EdgeInsets.only(left:5,right:5),
child:Row(
children: <Widget>[
Expanded(child:RaisedButton(
color: Colors.blue,
onPressed: () { Navigator.pop(context, false);
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(3)),
color: Colors.blue,
),
padding: const EdgeInsets.all(10.0),
child:
const Text('Close',),
),
)),
],
)),
],)),
margin: EdgeInsets.only(bottom: 50, left: 12, right: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
);
},
transitionBuilder: (context, anim1, anim2, child) {
return SlideTransition(
position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim1),
child: child,
);
},
);
}
}
onResume: (Map<String, dynamic> message) async {
if(type_id=='1' ){
showGeneralDialog(
barrierLabel: "General Information",
barrierDismissible: false,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: Duration(milliseconds: 1200),
context: context,
pageBuilder: (context, anim1, anim2) {
return Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 400,
child: SingleChildScrollView(child:Column(children: [
SizedBox(height: 10,),
Center(child:Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(0),
child:Material(
color: Colors.white,
child:Text("Information!",style:TextStyle(
fontFamily: 'Montserrat', fontSize: 20.0, color: Colors.black,fontWeight: FontWeight.bold)
))),
],))),
Container(
padding: EdgeInsets.all(5),
child:Material(
color: Colors.white,
child:Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(children: [
Image.asset("assets/640x360.png",fit: BoxFit.cover,
height: 180,),
Image.network(item_thumbnail_name),
],),
Center(child:Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_title,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.pink,
fontSize: 15,fontWeight: FontWeight.bold),
))),
Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_description+"...",
maxLines: 4,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.grey,
fontSize: 12,fontWeight: FontWeight.normal),
)),
],))),
Container(
padding: EdgeInsets.only(left:5,right:5),
child:Row(
children: <Widget>[
Expanded(child:RaisedButton(
color: Colors.blue,
onPressed: () { Navigator.pop(context, false);
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(3)),
color: Colors.blue,
),
padding: const EdgeInsets.all(10.0),
child:
const Text('Close',),
),
)),
],
)),
],)),
margin: EdgeInsets.only(bottom: 50, left: 12, right: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
);
},
transitionBuilder: (context, anim1, anim2, child) {
return SlideTransition(
position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim1),
child: child,
);
},
);
}
} onLaunch: (Map<String, dynamic> message) async {
if(type_id=='1' ){
showGeneralDialog(
barrierLabel: "General Information",
barrierDismissible: false,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: Duration(milliseconds: 1200),
context: context,
pageBuilder: (context, anim1, anim2) {
return Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 400,
child: SingleChildScrollView(child:Column(children: [
SizedBox(height: 10,),
Center(child:Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(0),
child:Material(
color: Colors.white,
child:Text("Information!",style:TextStyle(
fontFamily: 'Montserrat', fontSize: 20.0, color: Colors.black,fontWeight: FontWeight.bold)
))),
],))),
Container(
padding: EdgeInsets.all(5),
child:Material(
color: Colors.white,
child:Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(children: [
Image.asset("assets/640x360.png",fit: BoxFit.cover,
height: 180,),
Image.network(item_thumbnail_name),
],),
Center(child:Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_title,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.pink,
fontSize: 15,fontWeight: FontWeight.bold),
))),
Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Text(item_description+"...",
maxLines: 4,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.grey,
fontSize: 12,fontWeight: FontWeight.normal),
)),
],))),
Container(
padding: EdgeInsets.only(left:5,right:5),
child:Row(
children: <Widget>[
Expanded(child:RaisedButton(
color: Colors.blue,
onPressed: () { Navigator.pop(context, false);
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(3)),
color: Colors.blue,
),
padding: const EdgeInsets.all(10.0),
child:
const Text('Close',),
),
)),
],
)),
],)),
margin: EdgeInsets.only(bottom: 50, left: 12, right: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
);
},
transitionBuilder: (context, anim1, anim2, child) {
return SlideTransition(
position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim1),
child: child,
);
},
);
}
}
}
So after looking at my code line by line and troubleshoot I was able to figure that item_description= message['data']['item_description'];
in onLaunch so I added it like below:
onLaunch: (Map<String, dynamic> message) async {
item_description= message['data']['item_description'];
}
After adding this to my onLaunch I did get the error again and my showdialog displays.