init firebase
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:example/state/init_data.dart';
|
||||
import 'package:example/pages/choose_user_page.dart';
|
||||
import 'package:example/pages/splash_screen.dart';
|
||||
import 'package:example/routes/app_routes.dart';
|
||||
import 'package:example/routes/routes.dart';
|
||||
import 'package:example/state/init_data.dart';
|
||||
import 'package:example/utils/app_config.dart';
|
||||
import 'package:example/utils/local_notification_observer.dart';
|
||||
import 'package:example/utils/localizations.dart';
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// File generated by FlutterFire CLI.
|
||||
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
|
||||
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) {
|
||||
return web;
|
||||
}
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
return android;
|
||||
case TargetPlatform.iOS:
|
||||
return ios;
|
||||
case TargetPlatform.macOS:
|
||||
return macos;
|
||||
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 web = FirebaseOptions(
|
||||
apiKey: 'AIzaSyA4Obi2paSQ1IZZ88OcMC98DJlpV16DAzE',
|
||||
appId: '1:674907137625:web:a4b97e5d080ec165d7f348',
|
||||
messagingSenderId: '674907137625',
|
||||
projectId: 'stream-chat-internal',
|
||||
authDomain: 'stream-chat-internal.firebaseapp.com',
|
||||
databaseURL: 'https://stream-chat-internal.firebaseio.com',
|
||||
storageBucket: 'stream-chat-internal.appspot.com',
|
||||
measurementId: 'G-F2RV4P139L',
|
||||
);
|
||||
|
||||
static const FirebaseOptions android = FirebaseOptions(
|
||||
apiKey: 'AIzaSyBArS4RH7lUn3xbD-jhzWl5hVWZhliRgY0',
|
||||
appId: '1:674907137625:android:e55b74fd5747e39ad7f348',
|
||||
messagingSenderId: '674907137625',
|
||||
projectId: 'stream-chat-internal',
|
||||
databaseURL: 'https://stream-chat-internal.firebaseio.com',
|
||||
storageBucket: 'stream-chat-internal.appspot.com',
|
||||
);
|
||||
|
||||
static const FirebaseOptions ios = FirebaseOptions(
|
||||
apiKey: 'AIzaSyBTAsaKFUPLAJqfsLiz0yPUVzwrgJkOwSE',
|
||||
appId: '1:674907137625:ios:cafb9fb076a453c4d7f348',
|
||||
messagingSenderId: '674907137625',
|
||||
projectId: 'stream-chat-internal',
|
||||
databaseURL: 'https://stream-chat-internal.firebaseio.com',
|
||||
storageBucket: 'stream-chat-internal.appspot.com',
|
||||
androidClientId: '674907137625-2scfo9a5cs074dced5vhm712ej6hhtpm.apps.googleusercontent.com',
|
||||
iosClientId: '674907137625-flarfn9cefu4lermgpbc4b8rm8l15ian.apps.googleusercontent.com',
|
||||
iosBundleId: 'io.getstream.flutter',
|
||||
);
|
||||
|
||||
static const FirebaseOptions macos = FirebaseOptions(
|
||||
apiKey: 'AIzaSyBTAsaKFUPLAJqfsLiz0yPUVzwrgJkOwSE',
|
||||
appId: '1:674907137625:ios:c719c700198c28b1d7f348',
|
||||
messagingSenderId: '674907137625',
|
||||
projectId: 'stream-chat-internal',
|
||||
databaseURL: 'https://stream-chat-internal.firebaseio.com',
|
||||
storageBucket: 'stream-chat-internal.appspot.com',
|
||||
androidClientId: '674907137625-2scfo9a5cs074dced5vhm712ej6hhtpm.apps.googleusercontent.com',
|
||||
iosClientId: '674907137625-p3msks3snq0h22l7ekpqcf0frr0vt8mg.apps.googleusercontent.com',
|
||||
iosBundleId: 'io.getstream.streamChatV1',
|
||||
);
|
||||
}
|
||||
@@ -4,10 +4,32 @@ import 'package:example/utils/app_config.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
|
||||
import 'package:example/app.dart';
|
||||
|
||||
void main() async {
|
||||
import 'firebase_options.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
print("#firebase; PN_2 ");
|
||||
await Firebase.initializeApp();
|
||||
|
||||
// If you're going to use other Firebase services in the background, such as Firestore,
|
||||
// make sure you call `initializeApp` before using other Firebase services.
|
||||
print('[setupPushNotifications] newMessage: ${message.toMap()}');
|
||||
}
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
print("#firebase; PN_1");
|
||||
await Firebase.initializeApp();
|
||||
Firebase.apps.forEach((it) {
|
||||
print("#firebase; app: $it");
|
||||
});
|
||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||
/// Captures errors reported by the Flutter framework.
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
if (kDebugMode) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:example/routes/routes.dart';
|
||||
import 'package:example/utils/app_config.dart';
|
||||
import 'package:example/utils/localizations.dart';
|
||||
import 'package:example/widgets/channel_list.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
@@ -125,10 +126,39 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
||||
FlutterAppBadger.removeBadge();
|
||||
}
|
||||
});
|
||||
unawaited(_setupPushNotifications(StreamChat.of(context).client));
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> _setupPushNotifications(StreamChatClient client) async {
|
||||
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
NotificationSettings settings = await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: false,
|
||||
badge: true,
|
||||
carPlay: false,
|
||||
criticalAlert: false,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
|
||||
print('[setupPushNotifications] #firebase; settings: ${settings.authorizationStatus}');
|
||||
|
||||
String? token = await FirebaseMessaging.instance.getToken();
|
||||
if (token != null) {
|
||||
final result = await client.addDevice(token, PushProvider.firebase);
|
||||
print('[setupPushNotifications] #firebase; token registered: $token');
|
||||
}
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen((token) async {
|
||||
final result = await client.addDevice(token, PushProvider.firebase);
|
||||
print('[setupPushNotifications] #firebase; token refreshed: $token');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
badgeListener?.cancel();
|
||||
|
||||
Reference in New Issue
Block a user