|
|
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:latlong2/latlong.dart';
|
|
|
import 'navigation/navigation_page.dart';
|
|
|
import 'challenges/challenge_page.dart';
|
|
|
+import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
+import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
|
|
import 'firebase_options.dart';
|
|
|
|
|
|
@@ -11,11 +13,13 @@ void main() async {
|
|
|
await Firebase.initializeApp(
|
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
|
);
|
|
|
+ handleMessages();
|
|
|
runApp(const PhysiGo());
|
|
|
}
|
|
|
|
|
|
class PhysiGo extends StatelessWidget {
|
|
|
const PhysiGo({Key? key}) : super(key: key);
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return MaterialApp(
|
|
|
@@ -52,20 +56,53 @@ class HomePage extends StatelessWidget {
|
|
|
},
|
|
|
child: const Text('Navigation')),
|
|
|
),
|
|
|
- Center(
|
|
|
- child: TextButton(
|
|
|
- onPressed: () {
|
|
|
- Navigator.push(
|
|
|
- context,
|
|
|
- MaterialPageRoute(
|
|
|
- // Example on how to use NavigationPage
|
|
|
- builder: (context) => const ChallengePage(),
|
|
|
- ),
|
|
|
- );
|
|
|
- },
|
|
|
- child: const Text('Challenges')),
|
|
|
- ),],
|
|
|
- )
|
|
|
- );
|
|
|
+ Center(
|
|
|
+ child: TextButton(
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.push(
|
|
|
+ context,
|
|
|
+ MaterialPageRoute(
|
|
|
+ // Example on how to use NavigationPage
|
|
|
+ builder: (context) => const ChallengePage(),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ child: const Text('Challenges')),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+void handleMessages() async {
|
|
|
+ FirebaseMessaging messaging = FirebaseMessaging.instance;
|
|
|
+ final _firestore = FirebaseFirestore.instance;
|
|
|
+
|
|
|
+ NotificationSettings settings = await messaging.requestPermission(
|
|
|
+ alert: true,
|
|
|
+ announcement: false,
|
|
|
+ badge: true,
|
|
|
+ carPlay: false,
|
|
|
+ criticalAlert: false,
|
|
|
+ provisional: false,
|
|
|
+ sound: true,
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
|
|
+ print('Got a message whilst in the foreground!');
|
|
|
+ print('Message data: ${message.data}');
|
|
|
+
|
|
|
+ if (message.notification != null) {
|
|
|
+ print('Message also contained a notification: ${message.notification}');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ messaging.onTokenRefresh.listen((fcmToken) async {
|
|
|
+ final fcmToken = await messaging.getToken();
|
|
|
+ final user = _firestore.collection('Users').doc('tlmysIvwTBaoZKWqBofx');
|
|
|
+ user.update({
|
|
|
+ 'token': fcmToken,
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|