Skip to content

Commit afbf8a9

Browse files
committed
Update example
1 parent 8c554ca commit afbf8a9

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

example/lib/main.dart

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ enum RegistrationMethod {
4242
void main() async {
4343
WidgetsFlutterBinding.ensureInitialized();
4444
if (kIsWeb) {
45-
// Add firebase config here
46-
const options = FirebaseOptions(
47-
apiKey: '',
48-
appId: '',
49-
messagingSenderId: '',
50-
projectId: '',
51-
authDomain: '',
52-
databaseURL: '',
53-
storageBucket: '',
54-
measurementId: '',
55-
);
56-
// For web apps only
57-
await Firebase.initializeApp(options: options);
45+
// Get registration method
46+
final registrationMethod = RegistrationMethod.loadFromEnvironment() ?? RegistrationMethod.env;
47+
48+
// if web, we use the requested registration method for firebase registration only
49+
if(registrationMethod == RegistrationMethod.firebase) {
50+
// Add firebase config here
51+
const options = FirebaseOptions(
52+
apiKey: '',
53+
appId: '',
54+
messagingSenderId: '',
55+
projectId: '',
56+
authDomain: '',
57+
databaseURL: '',
58+
storageBucket: '',
59+
measurementId: '',
60+
);
61+
// For web apps only
62+
await Firebase.initializeApp(options: options);
63+
}
5864
} else {
5965
// For Android, iOS - Firebase will search for google-services.json in android/app directory or GoogleService-Info.plist in ios/Runner directory respectively.
6066
await Firebase.initializeApp();
@@ -120,7 +126,8 @@ class _AppState extends State<App> {
120126
printDebug("voip-registering access token");
121127

122128
String? androidToken;
123-
if (Platform.isAndroid || kIsWeb) {
129+
if(!kIsWeb && Platform.isAndroid) {
130+
// Get device token for Android only
124131
androidToken = await FirebaseMessaging.instance.getToken();
125132
printDebug("androidToken is ${androidToken!}");
126133
}

0 commit comments

Comments
 (0)