Skip to content

Instantly share code, notes, and snippets.

@SteveOye
Last active February 2, 2023 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveOye/fd6fedbe4da804e1e2a3c40138660997 to your computer and use it in GitHub Desktop.
Save SteveOye/fd6fedbe4da804e1e2a3c40138660997 to your computer and use it in GitHub Desktop.
//import all packages used
void main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
NotificationApi.init();
//initial firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const DruveApp());
}
class _NotificationAppState extends State<NotificationApp> {
@override
void initState() {
super.initState();
notificationHandler(); // init the method on state of the application
}
//create a method that handles notification
void notificationHandler() {
FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;
FirebaseMessaging.onMessage.listen((event) async {
await NotificationApi.pushNotification(event);
});
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: ControllerBinding(),
fallbackLocale: const Locale('en_US'),
getPages: pages,
initialRoute: '/',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment