Guest User

Untitled

a guest
Feb 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // main.dart
  2.  
  3. void main() {
  4. SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
  5. runApp(MyApp());
  6. }
  7.  
  8. class MyApp extends StatefulWidget {
  9. @override
  10. State<StatefulWidget> createState() => _AppState();
  11. }
  12.  
  13. class _AppState extends State<MyApp> {
  14. final FirebaseMessaging _fm = new FirebaseMessaging();
  15. final GlobalKey<NavigatorState> navigatorKey =
  16. GlobalKey(debugLabel: 'Main Navigator');
  17.  
  18. final routes = {
  19. // ...
  20. };
  21.  
  22. fcmSetting(context) {
  23. _fm.configure(
  24. onLaunch: (Map<String, dynamic> message) {
  25. pushTo(message); // not work
  26. },
  27. onMessage: (Map<String, dynamic> message) {
  28. print('onMessage $message'); // it run well
  29. onMessageSend(message); // but it's not
  30. },
  31. onResume: (Map<String, dynamic> message) {
  32. pushTo(message); // not work
  33. },
  34. );
  35. _fm.requestNotificationPermissions(
  36. const IosNotificationSettings(sound: true, badge: true, alert: true));
  37.  
  38. _fm.getToken().then((token) {
  39. DBFactory.getInstance().insert('fcmToken', token);
  40. });
  41. }
  42.  
  43. pushTo(message) {
  44. if (message['type'] == 'notice') {
  45. Navigator.of(navigatorKey.currentContext).push(
  46. MaterialPageRoute(builder: (_) => NoticeDetailScreen(message['id'])));
  47. }
  48. }
  49.  
  50. onMessageSend(message) {
  51. showDialog(
  52. context: context,
  53. builder: (bd) => new AlertDialog(
  54. title: LText('메세지 도착!'),
  55. content: LText('$message'),
  56. actions: <Widget>[
  57. LFlatButton(
  58. text: '확인', onPressed: () => Navigator.of(bd).pop()),
  59. ],
  60. ));
  61. }
  62.  
  63. @override
  64. Widget build(BuildContext context) {
  65. fcmSetting(context);
  66. return new MaterialApp(
  67. navigatorKey: navigatorKey,
  68. title: 'App title',
  69. initialRoute: '/',
  70. routes: routes,
  71. );
  72. }
  73. }
Add Comment
Please, Sign In to add comment