Created
July 7, 2020 00:23
-
-
Save iqan/0e211fc58848f2b410149f4364a2c186 to your computer and use it in GitHub Desktop.
Flutter Mobile Application receiving notifications from Azure Notification hub
This file contains hidden or 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:flutter/material.dart'; | |
import 'package:azure_notificationhubs_flutter/azure_notificationhubs_flutter.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Iqans Push Notification Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Notification Demo'), | |
), | |
body: Center( | |
child: Text('Notifications Demo Home Page'), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
AzureNotificationhubsFlutter().configure( | |
onLaunch: (Map<String, dynamic> notification) async { | |
print('anh onLaunch: $notification'); | |
}, | |
onResume: (Map<String, dynamic> notification) async { | |
print('anh onResume: $notification'); | |
}, | |
onMessage: (Map<String, dynamic> notification) async { | |
print('anh onMessage: $notification'); | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text(notification['message']), | |
)); | |
}, | |
onToken: (dynamic notification) async { | |
print('anh onToken: $notification'); | |
}, | |
); | |
}, | |
child: Icon( | |
Icons.notifications_active, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment