-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_local.dart
50 lines (41 loc) · 1.37 KB
/
main_local.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'dart:io';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:party_radar/app.dart';
import 'package:party_radar/flavors/flavor_config.dart';
import 'package:party_radar/firebase_options_dev.dart';
import 'package:party_radar/services/user_service.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DevFirebaseOptions.currentPlatform);
await _initFCM();
FlavorConfig(
flavor: Flavor.local,
color: Colors.deepPurpleAccent,
values: FlavorValues(
baseUrl:
"http://${Platform.isAndroid ? '10.0.2.2' : 'localhost'}:8080/api",
),
);
runApp(const PartyRadarApp());
}
Future<void> _initFCM() async {
await FirebaseMessaging.instance.requestPermission();
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
FirebaseMessaging.instance.getToken().then((token) {
if (FirebaseAuth.instance.currentUser != null) {
UserService.updateFCMToken(token);
}
});
FirebaseMessaging.instance.onTokenRefresh.listen((token) {
if (FirebaseAuth.instance.currentUser != null) {
UserService.updateFCMToken(token);
}
});
}