Skip to content

Commit 745b09c

Browse files
authored
Merge pull request #11 from talkjs/feat/push-notifications
Feat/push notifications
2 parents 256b442 + b9b1a97 commit 745b09c

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// File generated by FlutterFire CLI.
2+
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
3+
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
4+
import 'package:flutter/foundation.dart'
5+
show defaultTargetPlatform, kIsWeb, TargetPlatform;
6+
7+
/// Default [FirebaseOptions] for use with your Firebase apps.
8+
///
9+
/// Example:
10+
/// ```dart
11+
/// import 'firebase_options.dart';
12+
/// // ...
13+
/// await Firebase.initializeApp(
14+
/// options: DefaultFirebaseOptions.currentPlatform,
15+
/// );
16+
/// ```
17+
class DefaultFirebaseOptions {
18+
static FirebaseOptions get currentPlatform {
19+
if (kIsWeb) {
20+
throw UnsupportedError(
21+
'DefaultFirebaseOptions have not been configured for web - '
22+
'you can reconfigure this by running the FlutterFire CLI again.',
23+
);
24+
}
25+
switch (defaultTargetPlatform) {
26+
case TargetPlatform.android:
27+
throw UnsupportedError(
28+
'DefaultFirebaseOptions have not been configured for android - '
29+
'you can reconfigure this by running the FlutterFire CLI again.',
30+
);
31+
case TargetPlatform.iOS:
32+
throw UnsupportedError(
33+
'DefaultFirebaseOptions have not been configured for ios - '
34+
'you can reconfigure this by running the FlutterFire CLI again.',
35+
);
36+
case TargetPlatform.macOS:
37+
throw UnsupportedError(
38+
'DefaultFirebaseOptions have not been configured for macos - '
39+
'you can reconfigure this by running the FlutterFire CLI again.',
40+
);
41+
case TargetPlatform.windows:
42+
throw UnsupportedError(
43+
'DefaultFirebaseOptions have not been configured for windows - '
44+
'you can reconfigure this by running the FlutterFire CLI again.',
45+
);
46+
case TargetPlatform.linux:
47+
throw UnsupportedError(
48+
'DefaultFirebaseOptions have not been configured for linux - '
49+
'you can reconfigure this by running the FlutterFire CLI again.',
50+
);
51+
default:
52+
throw UnsupportedError(
53+
'DefaultFirebaseOptions are not supported for this platform.',
54+
);
55+
}
56+
}
57+
}

examples/push_notifications/lib/main.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import 'firebase_options.dart';
55

66
Future<void> main() async {
77
WidgetsFlutterBinding.ensureInitialized();
8-
await Firebase.initializeApp(
9-
options: DefaultFirebaseOptions.currentPlatform,
10-
);
118

12-
await registerPushNotificationHandlers(
9+
if (Platform.isAndroid) {
10+
await Firebase.initializeApp(
11+
options: DefaultFirebaseOptions.currentPlatform,
12+
);
13+
}
14+
15+
await Talk.registerPushNotificationHandlers(
1316
androidChannel: const AndroidChannel(
1417
channelId: 'com.talkjs.flutter_push_example.messages',
1518
channelName: 'Messages',

lib/talkjs_flutter.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class Talk {
3232
final hash = digest.toString().toLowerCase();
3333
return hash.substring(0, 20);
3434
}
35-
}
3635

37-
Future<void> registerPushNotificationHandlers({AndroidChannel? androidChannel, IOSPermissions? iosPermissions}) async {
38-
if ((Platform.isAndroid) && (androidChannel != null)) {
39-
await registerAndroidPushNotificationHandlers(androidChannel);
40-
}
36+
static Future<void> registerPushNotificationHandlers({AndroidChannel? androidChannel, IOSPermissions? iosPermissions}) async {
37+
if ((Platform.isAndroid) && (androidChannel != null)) {
38+
await registerAndroidPushNotificationHandlers(androidChannel);
39+
}
4140

42-
if ((Platform.isIOS) && (iosPermissions != null)) {
43-
await registerIOSPushNotificationHandlers(iosPermissions);
41+
if ((Platform.isIOS) && (iosPermissions != null)) {
42+
await registerIOSPushNotificationHandlers(iosPermissions);
43+
}
4444
}
4545
}

0 commit comments

Comments
 (0)