В моем приложении я реализовал постоянный AppBar и заменил контекст через панель навигации, как показано ниже. Я не знаю, что здесь не так. Я инициализирую конфигурацию и локальное уведомление, и я не уверен, что это происходит из-за конфликта, потому что он работал нормально до того, как я реализовал постоянный appBar. Я не получаю уведомления ни о каком обратном вызове вообще сейчас. Что я здесь не так делаю? Вот мой код:
class Root extends StatefulWidget {
@override
_RootState createState() => _RootState();
}
class _RootState extends State<Root> {
Widget body = Home();
String title = "Home";
Widget action;
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
localNoficationInitializer();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
showNotification(
message['notification']['title'], message['notification']['body']);
print("onMessage: $message");
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
super.initState();
}
void localNoficationInitializer() async {
await flutterLocalNotificationsPlugin.initialize(
InitializationSettings(
AndroidInitializationSettings('@mipmap/ic_launcher'),
IOSInitializationSettings()),
onSelectNotification: onSelectNotification);
}
void showNotification(String title, String body) async {
await _notification(title, body);
}
Future<void> _notification(String title, String body) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'onMessage', 'Notification', 'Local Notification',
importance: Importance.Max,
priority: Priority.High,
sound: 'sound',
ticker: 'test');
var iOSChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSChannelSpecifics);
await flutterLocalNotificationsPlugin
.show(0, title, body, platformChannelSpecifics, payload: 'test');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title??"Home"),
),
drawer: Drawer(
child: Stack(
children: [
ListView(
children: [
ListTile(
dense: true,
title: Text('Home',
style: Theme.of(context).textTheme.subhead),
leading: Icon(Icons.home, color: iconColor),
onTap: () {
Navigator.of(context).pop();
setState(() {
body = Home();
title = "Home";
});
},
),
ListTile(
dense: true,
title: Text('Downloads',
style: Theme.of(context).textTheme.subhead),
leading: Icon(Icons.archive, color: iconColor),
onTap: () {
Navigator.pop(context);
setState(() {
body = Downloads();
title = "Downloads";
});
}),
ListTile(
dense: true,
title: Text('LogOut',
style: Theme.of(context).textTheme.subhead),
leading: Icon(
AntDesign.logout,
color: iconColor,
),
onTap: () {
showDialog(
context: context,
child: new AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6)),
title: new Text('Logout'),
content: new Text(
'You are going to be logged out of this application. Are you sure?'),
actions: <Widget>[
new FlatButton(
onPressed: () => Navigator.pop(context),
child: new Text('No'),
),
new FlatButton(
onPressed: () => logout(context),
child: new Text('Yes'),
),
],
),
);
}),
],
),
],
),
),
body: body ?? Home());
}
Future onSelectNotification(String payload) async {
showDialog(
context: context,
builder: (_) {
return new AlertDialog(
title: Text("PayLoad"),
content: Text("Payload : $payload"),
);
},
);
}
}