-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yolcura1@gmail.com
authored and
yolcura1@gmail.com
committed
Apr 26, 2020
1 parent
f2083b9
commit 24b7c59
Showing
6 changed files
with
204 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.10.1\\\\","dependencies":["firebase_core"]},{"name":"firebase_analytics","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_analytics-2.1.1+3\\\\","dependencies":[]},{"name":"firebase_auth","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.8.4+5\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.3.4\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.0.1+3\\\\","dependencies":[]},{"name":"in_app_purchase","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\in_app_purchase-0.3.1+2\\\\","dependencies":[]},{"name":"webview_flutter","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter-0.3.19+9\\\\","dependencies":[]}],"android":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.10.1\\\\","dependencies":["firebase_core"]},{"name":"firebase_analytics","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_analytics-2.1.1+3\\\\","dependencies":[]},{"name":"firebase_auth","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.8.4+5\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.3.4\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.0.1+3\\\\","dependencies":[]},{"name":"in_app_purchase","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\in_app_purchase-0.3.1+2\\\\","dependencies":[]},{"name":"webview_flutter","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter-0.3.19+9\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"cloud_firestore","dependencies":["firebase_core"]},{"name":"firebase_analytics","dependencies":[]},{"name":"firebase_auth","dependencies":["firebase_core"]},{"name":"firebase_core","dependencies":[]},{"name":"google_sign_in","dependencies":[]},{"name":"in_app_purchase","dependencies":[]},{"name":"webview_flutter","dependencies":[]}],"date_created":"2020-04-23 23:24:59.768231","version":"1.15.17"} | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.12.11\\\\","dependencies":["firebase_core"]},{"name":"firebase_analytics","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_analytics-2.1.1+3\\\\","dependencies":[]},{"name":"firebase_auth","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.11.1+12\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_messaging","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-5.1.8\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.0.1+3\\\\","dependencies":[]},{"name":"in_app_purchase","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\in_app_purchase-0.3.1+2\\\\","dependencies":[]},{"name":"webview_flutter","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter-0.3.19+9\\\\","dependencies":[]}],"android":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.12.11\\\\","dependencies":["firebase_core"]},{"name":"firebase_analytics","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_analytics-2.1.1+3\\\\","dependencies":[]},{"name":"firebase_auth","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.11.1+12\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_messaging","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-5.1.8\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.0.1+3\\\\","dependencies":[]},{"name":"in_app_purchase","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\in_app_purchase-0.3.1+2\\\\","dependencies":[]},{"name":"webview_flutter","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter-0.3.19+9\\\\","dependencies":[]}],"macos":[{"name":"firebase_core","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"firebase_core_web","path":"C:\\\\Users\\\\asus\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core_web-0.1.1+2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"cloud_firestore","dependencies":["firebase_core"]},{"name":"firebase_analytics","dependencies":[]},{"name":"firebase_auth","dependencies":["firebase_core"]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_messaging","dependencies":[]},{"name":"google_sign_in","dependencies":[]},{"name":"in_app_purchase","dependencies":[]},{"name":"webview_flutter","dependencies":[]}],"date_created":"2020-04-26 01:52:29.800497","version":"1.15.17"} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
|
||
|
||
class MessageHandler { | ||
final Firestore _db = Firestore.instance; | ||
final FirebaseMessaging _fcm = FirebaseMessaging(); | ||
|
||
StreamSubscription iosSubscription; | ||
|
||
|
||
void initState(BuildContext context) { | ||
|
||
if (Platform.isIOS) { | ||
iosSubscription = _fcm.onIosSettingsRegistered.listen((data) { | ||
print(data); | ||
_saveDeviceToken(); | ||
}); | ||
|
||
_fcm.requestNotificationPermissions(IosNotificationSettings()); | ||
} else { | ||
_saveDeviceToken(); | ||
} | ||
|
||
_fcm.configure( | ||
onMessage: (Map<String, dynamic> message) async { | ||
print("onMessage: $message"); | ||
/* | ||
final snackbar = SnackBar( | ||
content: Text(message['notification']['title']), | ||
action: SnackBarAction( | ||
label: 'Go', | ||
onPressed: () => null, | ||
), | ||
); | ||
Scaffold.of(context).showSnackBar(snackbar); | ||
*/ | ||
|
||
|
||
showDialog( | ||
context: context, | ||
builder: (context) => AlertDialog( | ||
content: ListTile( | ||
title: Text(message['notification']['title']), | ||
subtitle: Text(message['notification']['body']), | ||
), | ||
actions: <Widget>[ | ||
FlatButton( | ||
color: Colors.amber, | ||
child: Text('Ok'), | ||
onPressed: () => Navigator.of(context).pop(), | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
onLaunch: (Map<String, dynamic> message) async { | ||
print("onLaunch: $message"); | ||
// TODO optional | ||
}, | ||
onResume: (Map<String, dynamic> message) async { | ||
print("onResume: $message"); | ||
// TODO optional | ||
}, | ||
); | ||
|
||
} | ||
|
||
|
||
void disposeNotifications() { | ||
if (iosSubscription != null) iosSubscription.cancel(); | ||
|
||
} | ||
|
||
|
||
/// Get the token, save it to the database for current user | ||
_saveDeviceToken() async { | ||
// Get the current user | ||
String uid = 'jeffd23'; | ||
// FirebaseUser user = await _auth.currentUser(); | ||
|
||
// Get the token for this device | ||
String fcmToken = await _fcm.getToken(); | ||
|
||
// Save it to Firestore | ||
if (fcmToken != null) { | ||
var tokens = _db | ||
.collection('users') | ||
.document(uid) | ||
.collection('tokens') | ||
.document(fcmToken); | ||
|
||
await tokens.setData({ | ||
'token': fcmToken, | ||
'createdAt': FieldValue.serverTimestamp(), // optional | ||
'platform': Platform.operatingSystem // optional | ||
}); | ||
} | ||
} | ||
|
||
/// Subscribe the user to a topic | ||
_subscribeToTopic() async { | ||
// Subscribe the user to a topic | ||
_fcm.subscribeToTopic('puppies'); | ||
} | ||
} |
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
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
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