Created
September 29, 2018 11:01
-
-
Save naumanahmed19/805601aca49e5891e7c753a0ceeddb93 to your computer and use it in GitHub Desktop.
A very simple example for firebase topics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:firebase_messaging/firebase_messaging.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MaterialApp( | |
home: MyApp(), | |
)); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
FirebaseMessaging _firebaseMessaging = new FirebaseMessaging(); | |
@override | |
void initState() { | |
//for example your topic name is news | |
_firebaseMessaging.subscribeToTopic('news'); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('text'), | |
), | |
body: Container( | |
padding: EdgeInsets.all(32.0), | |
child: Center( | |
child: Column( | |
children: <Widget>[], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment