I am making a simple application which uses a WebView
widget as it's main widget. I want to be able to send a notification to all users from the firebase console. The application has no authentication.
My MessageHandler (defined in main.dart)
class MessageHandler extends StatefulWidget {
@override
_MessageHandlerState createState() => _MessageHandlerState();
}
class _MessageHandlerState extends State<MessageHandler>{
final FirebaseMessaging _fcm = FirebaseMessaging();
@override
void initState(){
super.initState();
_fcm.configure(
onMessage: (Map<String, dynamic> message) async {
print("here");
print("onMessage: $message");
final snackbar = SnackBar(
content: Text(message['notification']['title']),
);
},
);
Main
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Simple App",
home: WebViewer()
);
}
}
The WebViewer Widget works so I have not added it to the question. On the Firebase Console, the message appears to have been sent
but the alert does not appear on the Android Emulator, nor does the snackbar
.
WebView
class WebViewer extends StatelessWidget {
final Completer<WebViewController> _controller = Completer<WebViewController>();
//FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("Event Viewer")),
),
body: WebView(
initialUrl: "https://google.com",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController){
_controller.complete(webViewController);
},
)
);