-
-
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
Showing
12 changed files
with
298 additions
and
45 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
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,29 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "530304958306", | ||
"project_id": "tail-app-408901", | ||
"storage_bucket": "tail-app-408901.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:530304958306:android:f6fa9441549b1656b2b63b", | ||
"android_client_info": { | ||
"package_name": "com.codel1417.tail_app" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyDce_fr8SP1W8NiOQtMvvGX4UgLEs1qiXI" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
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
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 @@ | ||
{"flutter":{"platforms":{"android":{"default":{"projectId":"tail-app-408901","appId":"1:530304958306:android:f6fa9441549b1656b2b63b","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"tail-app-408901","configurations":{"android":"1:530304958306:android:f6fa9441549b1656b2b63b","ios":"1:530304958306:ios:6b58cfb4dd10b9b6b2b63b"}}}}}} |
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,96 @@ | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
final fireLogger = Logger('Firebase'); | ||
|
||
@pragma('vm:entry-point') | ||
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async { | ||
fireLogger.info("Handling a background message: ${message.messageId}"); | ||
} | ||
|
||
Future<void> initFirebase() async { | ||
fireLogger.info("Begin init Firebase"); | ||
await Firebase.initializeApp(); | ||
FirebaseMessaging messaging = FirebaseMessaging.instance; | ||
messaging.app.setAutomaticDataCollectionEnabled(false); | ||
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); | ||
await messaging.subscribeToTopic("newsletter"); | ||
final notificationSettings = await messaging.requestPermission( | ||
provisional: true, | ||
sound: false, | ||
); | ||
NotificationSettings settings = await messaging.requestPermission( | ||
alert: true, | ||
announcement: false, | ||
badge: true, | ||
carPlay: false, | ||
criticalAlert: false, | ||
provisional: false, | ||
sound: false, | ||
); | ||
FirebaseMessaging.onMessage.listen((RemoteMessage message) async { | ||
fireLogger.info('Got a message whilst in the foreground!'); | ||
fireLogger.info('Message data: ${message.data}'); | ||
|
||
if (message.notification != null) { | ||
fireLogger.info('Message also contained a notification: ${message.notification}'); | ||
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( | ||
'newsletter', | ||
'Newsletter', | ||
channelDescription: 'Notifications from the Tail Company Newsletter', | ||
priority: Priority.low, | ||
playSound: false, | ||
enableVibration: false, | ||
enableLights: false, | ||
); | ||
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); | ||
await flutterLocalNotificationsPlugin?.show( | ||
message.notification.hashCode, | ||
message.notification?.title, | ||
message.notification?.body, | ||
notificationDetails, | ||
); | ||
} | ||
}); | ||
} | ||
|
||
Future<String?> getFirebaseToken() async { | ||
return await (FirebaseMessaging.instance).getToken(); | ||
} | ||
|
||
FlutterLocalNotificationsPlugin? flutterLocalNotificationsPlugin; | ||
|
||
Future<void> initNotificationPlugin() async { | ||
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); | ||
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project | ||
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings("@mipmap/ic_launcher"); | ||
const DarwinInitializationSettings initializationSettingsDarwin = DarwinInitializationSettings(defaultPresentSound: false, requestSoundPermission: false); | ||
const InitializationSettings initializationSettings = InitializationSettings( | ||
android: initializationSettingsAndroid, | ||
iOS: initializationSettingsDarwin, | ||
); | ||
await flutterLocalNotificationsPlugin?.initialize( | ||
initializationSettings, | ||
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, | ||
onDidReceiveBackgroundNotificationResponse: onDidReceiveBackgroundNotificationResponse, | ||
); | ||
} | ||
|
||
//Foreground | ||
void onDidReceiveNotificationResponse(NotificationResponse notificationResponse) async { | ||
final String? payload = notificationResponse.payload; | ||
if (notificationResponse.payload != null) { | ||
fireLogger.info('notification payload: $payload'); | ||
} | ||
} | ||
|
||
//background | ||
@pragma('vm:entry-point') | ||
void onDidReceiveBackgroundNotificationResponse(NotificationResponse notificationResponse) { | ||
final String? payload = notificationResponse.payload; | ||
if (notificationResponse.payload != null) { | ||
fireLogger.info('notification payload: $payload'); | ||
} | ||
} |
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,69 @@ | ||
// File generated by FlutterFire CLI. | ||
// ignore_for_file: type=lint | ||
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; | ||
import 'package:flutter/foundation.dart' | ||
show defaultTargetPlatform, kIsWeb, TargetPlatform; | ||
|
||
/// Default [FirebaseOptions] for use with your Firebase apps. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// import 'firebase_options.dart'; | ||
/// // ... | ||
/// await Firebase.initializeApp( | ||
/// options: DefaultFirebaseOptions.currentPlatform, | ||
/// ); | ||
/// ``` | ||
class DefaultFirebaseOptions { | ||
static FirebaseOptions get currentPlatform { | ||
if (kIsWeb) { | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for web - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
} | ||
switch (defaultTargetPlatform) { | ||
case TargetPlatform.android: | ||
return android; | ||
case TargetPlatform.iOS: | ||
return ios; | ||
case TargetPlatform.macOS: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for macos - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
case TargetPlatform.windows: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for windows - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
case TargetPlatform.linux: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for linux - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
default: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions are not supported for this platform.', | ||
); | ||
} | ||
} | ||
|
||
static const FirebaseOptions android = FirebaseOptions( | ||
apiKey: 'AIzaSyDce_fr8SP1W8NiOQtMvvGX4UgLEs1qiXI', | ||
appId: '1:530304958306:android:f6fa9441549b1656b2b63b', | ||
messagingSenderId: '530304958306', | ||
projectId: 'tail-app-408901', | ||
storageBucket: 'tail-app-408901.appspot.com', | ||
); | ||
|
||
static const FirebaseOptions ios = FirebaseOptions( | ||
apiKey: 'AIzaSyCTapi53i9GlNLzAo5DTeghb2uXWfSrHXg', | ||
appId: '1:530304958306:ios:6b58cfb4dd10b9b6b2b63b', | ||
messagingSenderId: '530304958306', | ||
projectId: 'tail-app-408901', | ||
storageBucket: 'tail-app-408901.appspot.com', | ||
iosBundleId: 'com.codel1417.tailApp', | ||
); | ||
|
||
} |
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
Oops, something went wrong.