78 lines
2.2 KiB
Dart
78 lines
2.2 KiB
Dart
//<com>
|
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
|
import 'package:firebase_core/firebase_core.dart'
|
|
show Firebase, FirebaseOptions;
|
|
import 'package:flutter/foundation.dart'
|
|
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
|
|
|
class DefaultFirebaseOptions {
|
|
static FirebaseOptions get currentPlatform {
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
return android;
|
|
case TargetPlatform.iOS:
|
|
return ios;
|
|
default:
|
|
throw UnsupportedError(
|
|
'DefaultFirebaseOptions are not supported for this platform.',
|
|
);
|
|
}
|
|
}
|
|
|
|
static const FirebaseOptions android = FirebaseOptions(
|
|
apiKey: 'AIzaSyC-3-ABWuy9LrYyAw_KxDRto4DanQ0sq9g',
|
|
appId: '1:281500445726:android:ddf52ac7b7f83cf5c4d20f',
|
|
messagingSenderId: '281500445726',
|
|
projectId: 'skychip2023-ecdff',
|
|
storageBucket: 'skychip2023-ecdff.firebasestorage.app',
|
|
);
|
|
|
|
static const FirebaseOptions ios = FirebaseOptions(
|
|
apiKey: 'AIzaSyACbp5aUKhLU1SMg8iIdm9WmNX7wxI7fVc',
|
|
appId: '1:281500445726:ios:b194ccffb92fb86cc4d20f',
|
|
messagingSenderId: '281500445726',
|
|
projectId: 'skychip2023-ecdff',
|
|
storageBucket: 'skychip2023-ecdff.firebasestorage.app',
|
|
iosBundleId: 'com.starlock.lock.local',
|
|
);
|
|
}
|
|
|
|
class FirebaseHelper {
|
|
factory FirebaseHelper() => _getInstance();
|
|
|
|
FirebaseHelper._internal();
|
|
|
|
static FirebaseHelper get instance => _getInstance();
|
|
static FirebaseHelper? _instance;
|
|
|
|
static FirebaseHelper _getInstance() {
|
|
_instance ??= FirebaseHelper._internal();
|
|
return _instance!;
|
|
}
|
|
|
|
Future<void> initApp() async {
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
}
|
|
|
|
Future<void> initSdk() async {
|
|
FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true);
|
|
}
|
|
|
|
Future<void> login(String userId) async {
|
|
FirebaseAnalytics.instance.setUserId(id: userId);
|
|
}
|
|
|
|
Future<void> trackEvent(
|
|
String eventName, Map<String, Object>? parameters) async {
|
|
FirebaseAnalytics.instance
|
|
.logEvent(name: eventName, parameters: parameters);
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
FirebaseAnalytics.instance.setUserId(id: '');
|
|
}
|
|
}
|
|
//</com>
|