Skip to content

Added Support to Specify FirebaseApp #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ PODS:
- Firebase/Auth (= 10.9.0)
- firebase_core
- Flutter
- firebase_core (2.13.0):
- firebase_core (3.2.0):
- Firebase/CoreOnly (= 10.9.0)
- Flutter
- firebase_storage (11.2.1):
Expand Down
4 changes: 4 additions & 0 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
url_launcher_linux
)

Expand Down
21 changes: 8 additions & 13 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: example
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
Expand All @@ -19,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: '>=2.19.0 <4.0.0'
sdk: ">=2.19.0 <4.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand All @@ -32,30 +29,29 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
faker: ^2.1.0
file_picker: ^5.3.0
firebase_auth: ^4.6.1
firebase_core: ^2.13.0
firebase_storage: ^11.2.1
file_picker: ^8.0.6
firebase_auth: ^5.1.2
firebase_core: ^3.2.0
firebase_storage: ^12.1.1
flutter:
sdk: flutter
flutter_chat_types: ^3.6.1
flutter_chat_ui: ^1.6.8
flutter_firebase_chat_core:
path: ../
http: ^0.13.6
image_picker: ^0.8.7+5
http: ^1.2.1
image_picker: ^1.1.2
mime: ^1.0.4
open_filex: ^4.3.2
path_provider: ^2.0.15

dev_dependencies:
dart_code_metrics: ^5.7.3
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.1
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter

Expand All @@ -64,7 +60,6 @@ dev_dependencies:

# The following section is specific to Flutter packages.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down
12 changes: 12 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

#include "generated_plugin_registrant.h"

#include <cloud_firestore/cloud_firestore_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <firebase_auth/firebase_auth_plugin_c_api.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <firebase_storage/firebase_storage_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
CloudFirestorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("CloudFirestorePluginCApi"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FirebaseAuthPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi"));
FirebaseCorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
FirebaseStoragePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseStoragePluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
4 changes: 4 additions & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
cloud_firestore
file_selector_windows
firebase_auth
firebase_core
firebase_storage
url_launcher_windows
)

Expand Down
23 changes: 22 additions & 1 deletion lib/src/firebase_chat_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ import 'util.dart';
/// FirebaseChatCore.instance to aceess methods.
class FirebaseChatCore {
FirebaseChatCore._privateConstructor() {
firebaseUser = FirebaseAuth.instance.currentUser;

FirebaseAuth.instance.authStateChanges().listen((User? user) {
firebaseUser = user;
});
}
FirebaseChatCore._privateConstructorForSpecifiedFirebaseApp(FirebaseApp app) {
firebaseUser = FirebaseAuth.instanceFor(app: app).currentUser;

FirebaseAuth.instanceFor(app: app).authStateChanges().listen((User? user) {
firebaseUser = user;
});
}

/// Config to set custom names for rooms and users collections. Also
/// see [FirebaseChatCoreConfig].
Expand All @@ -25,12 +34,24 @@ class FirebaseChatCore {

/// Current logged in user in Firebase. Does not update automatically.
/// Use [FirebaseAuth.authStateChanges] to listen to the state changes.
User? firebaseUser = FirebaseAuth.instance.currentUser;
User? firebaseUser;

/// Singleton instance.
static final FirebaseChatCore instance =
FirebaseChatCore._privateConstructor();

/// Returns an instance using a specified [FirebaseApp].
static FirebaseChatCore instanceFor({required FirebaseApp app}) {
final instance =
FirebaseChatCore._privateConstructorForSpecifiedFirebaseApp(app);
instance.config = FirebaseChatCoreConfig(
app.name,
instance.config.roomsCollectionName,
instance.config.usersCollectionName,
);
return instance;
}

/// Gets proper [FirebaseFirestore] instance.
FirebaseFirestore getFirebaseFirestore() => config.firebaseAppName != null
? FirebaseFirestore.instanceFor(
Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ environment:
flutter: '>=3.0.0'

dependencies:
cloud_firestore: ^4.7.1
firebase_auth: ^4.6.1
firebase_core: ^2.13.0
cloud_firestore: ^5.3.0
firebase_auth: ^5.2.0
firebase_core: ^3.4.0
flutter:
sdk: flutter
flutter_chat_types: ^3.6.1
meta: ^1.9.1
flutter_chat_types: ^3.6.2
meta: ^1.12.0

dev_dependencies:
dart_code_metrics: ^5.7.3
flutter_lints: ^2.0.1
dart_code_metrics: ^5.7.6
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter