Skip to content

Commit

Permalink
feat: add support for demo project (#11973)
Browse files Browse the repository at this point in the history
* feat: add support for demo project

* format

* demo instructions

* improve docs

* doc

* fix iOS

* Update docs/setup/_setup_main.md

Co-authored-by: Kevin Cheung <kevinthecheung@users.noreply.github.com>

* fix ios

* format

* format

---------

Co-authored-by: Kevin Cheung <kevinthecheung@users.noreply.github.com>
  • Loading branch information
Lyokone and kevinthecheung committed Jun 5, 2024
1 parent aba2dfa commit 859ec1d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/setup/_setup_main.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ flutterfire configure
flutter run
```

If you would rather use a demo project, you can start the [Firebase Emulator](https://firebase.google.com/docs/emulator-suite) and
in your `lib/main.dart` file initialize Firebase using `demoProjectId` (it should start with `demo-`):

```dart
await Firebase.initializeApp(
demoProjectId: "demo-project-id",
);
```



## **Step 4**: Add Firebase plugins {: #add-plugins}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class DefaultFirebaseOptions {
databaseURL:
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
storageBucket: 'flutterfire-e2e-tests.appspot.com',
androidClientId:
'406099696497-tvtvuiqogct1gs1s6lh114jeps7hpjm5.apps.googleusercontent.com',
iosClientId:
'406099696497-taeapvle10rf355ljcvq5dt134mkghmp.apps.googleusercontent.com',
iosBundleId: 'io.flutter.plugins.firebase.tests',
Expand Down
4 changes: 2 additions & 2 deletions packages/firebase_core/firebase_core/lib/firebase_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ library firebase_core;

import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
hide MethodChannelFirebaseApp, MethodChannelFirebase;
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';

export 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
show FirebaseOptions, defaultFirebaseAppName, FirebaseException;

part 'src/firebase_app.dart';
part 'src/firebase.dart';
part 'src/firebase_app.dart';
23 changes: 23 additions & 0 deletions packages/firebase_core/firebase_core/lib/src/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,30 @@ class Firebase {
static Future<FirebaseApp> initializeApp({
String? name,
FirebaseOptions? options,
String? demoProjectId,
}) async {
if (demoProjectId != null) {
late final String platformString;
if (defaultTargetPlatform == TargetPlatform.android) {
platformString = 'android';
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
platformString = 'ios';
} else {
// We use 'web' as the default platform for unknown platforms.
platformString = 'web';
}
FirebaseAppPlatform app = await _delegate.initializeApp(
options: FirebaseOptions(
apiKey: '',
appId: '1:1:$platformString:1',
messagingSenderId: '',
projectId: demoProjectId,
),
);

return FirebaseApp._(app);
}
FirebaseAppPlatform app = await _delegate.initializeApp(
name: name,
options: options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class MethodChannelFirebase extends FirebasePlatform {
// check to see if options are roughly identical (so we don't unnecessarily
// throw on minor differences such as platform specific keys missing
// e.g. hot reloads/restarts).
if (defaultApp != null && _options != null) {
if (defaultApp != null &&
_options != null &&
!_options.projectId.startsWith('demo-')) {
if (_options.apiKey != defaultApp.options.apiKey ||
(_options.databaseURL != null &&
_options.databaseURL != defaultApp.options.databaseURL) ||
Expand Down

0 comments on commit 859ec1d

Please sign in to comment.