Hi,
i have some troubles to get a simple push notification on a flutter mobile application using the firebase C# admin sdk :
my c# code look like :
private async Task SendPushNotification3Async(string val)
{
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile(@"e:\firebase-adminsdk.json"),
});
var condition = "'SQL' in topics";
var message = new FirebaseAdmin.Messaging.Message()
{
Notification = new FirebaseAdmin.Messaging.Notification()
{
Title = "simple title",
Body = "simple message",
},
Condition = condition
};
var response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
}
and on the flutter side :
import 'package:flutter/material.dart';
import 'package:sqlnotifapp/widget/messaging_widget.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final String appTitle = 'Simple Notifications';
@override
Widget build(BuildContext context) => MaterialApp(
title: appTitle,
home: MainPage(appTitle: appTitle),
);
}
class MainPage extends StatelessWidget {
final String appTitle;
const MainPage({this.appTitle});
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(appTitle),
),
body: MessagingWidget(),
);
}
the messaging widget :
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:sqlnotifapp/model/message.dart';
class MessagingWidget extends StatefulWidget {
@override
_MessagingWidgetState createState() => _MessagingWidgetState();
}
class _MessagingWidgetState extends State<MessagingWidget> {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
final List<Message> messages = [];
@override
void initState() {
super.initState();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
final notification = message['notification'];
setState(() {
messages.add(Message(
title: notification['title'], body: notification['body']));
});
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
_firebaseMessaging.subscribeToTopic('SQL');
final notification = message['data'];
setState(() {
messages.add(Message(
title: '${notification['title']}',
body: '${notification['body']}',
));
});
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
@override
Widget build(BuildContext context) => ListView(
children: messages.map(buildMessage).toList(),
);
Widget buildMessage(Message message) => ListTile(
title: Text(message.title),
subtitle: Text(message.body),
);
}
please not the line
_firebaseMessaging.subscribeToTopic('SQL');
when running this code there is no exception but there is also no push notifications :/
please note that i can get the push notifications from the firebase console to the mobile device without a problem .but not from the .net api .
what i am missing here ?
is there a way to send a message through the api to an android application using it's application ID, a topic or anything ?
any help or idea is welcome ,
thanks .