Skip to content

Commit 859ec1d

Browse files
Lyokonekevinthecheung
andauthoredJun 5, 2024··
feat: add support for demo project (#11973)
* 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>
1 parent aba2dfa commit 859ec1d

File tree

8 files changed

+41
-8
lines changed

8 files changed

+41
-8
lines changed
 

‎docs/setup/_setup_main.md

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ flutterfire configure
141141
flutter run
142142
```
143143
144+
If you would rather use a demo project, you can start the [Firebase Emulator](https://firebase.google.com/docs/emulator-suite) and
145+
in your `lib/main.dart` file initialize Firebase using `demoProjectId` (it should start with `demo-`):
146+
147+
```dart
148+
await Firebase.initializeApp(
149+
demoProjectId: "demo-project-id",
150+
);
151+
```
152+
153+
144154
145155
## **Step 4**: Add Firebase plugins {: #add-plugins}
146156

‎packages/firebase_core/firebase_core/example/ios/Flutter/AppFrameworkInfo.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>11.0</string>
24+
<string>12.0</string>
2525
</dict>
2626
</plist>

‎packages/firebase_core/firebase_core/example/ios/Runner.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
97C146E61CF9000F007C117D /* Project object */ = {
167167
isa = PBXProject;
168168
attributes = {
169-
LastUpgradeCheck = 1430;
169+
LastUpgradeCheck = 1510;
170170
ORGANIZATIONNAME = "The Chromium Authors";
171171
TargetAttributes = {
172172
97C146ED1CF9000F007C117D = {

‎packages/firebase_core/firebase_core/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎packages/firebase_core/firebase_core/example/lib/firebase_options.dart

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ class DefaultFirebaseOptions {
7070
databaseURL:
7171
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
7272
storageBucket: 'flutterfire-e2e-tests.appspot.com',
73-
androidClientId:
74-
'406099696497-tvtvuiqogct1gs1s6lh114jeps7hpjm5.apps.googleusercontent.com',
7573
iosClientId:
7674
'406099696497-taeapvle10rf355ljcvq5dt134mkghmp.apps.googleusercontent.com',
7775
iosBundleId: 'io.flutter.plugins.firebase.tests',

‎packages/firebase_core/firebase_core/lib/firebase_core.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ library firebase_core;
77

88
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
99
hide MethodChannelFirebaseApp, MethodChannelFirebase;
10-
import 'package:flutter/widgets.dart';
10+
import 'package:flutter/foundation.dart';
1111

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

15-
part 'src/firebase_app.dart';
1615
part 'src/firebase.dart';
16+
part 'src/firebase_app.dart';

‎packages/firebase_core/firebase_core/lib/src/firebase.dart

+23
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,30 @@ class Firebase {
3939
static Future<FirebaseApp> initializeApp({
4040
String? name,
4141
FirebaseOptions? options,
42+
String? demoProjectId,
4243
}) async {
44+
if (demoProjectId != null) {
45+
late final String platformString;
46+
if (defaultTargetPlatform == TargetPlatform.android) {
47+
platformString = 'android';
48+
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
49+
defaultTargetPlatform == TargetPlatform.macOS) {
50+
platformString = 'ios';
51+
} else {
52+
// We use 'web' as the default platform for unknown platforms.
53+
platformString = 'web';
54+
}
55+
FirebaseAppPlatform app = await _delegate.initializeApp(
56+
options: FirebaseOptions(
57+
apiKey: '',
58+
appId: '1:1:$platformString:1',
59+
messagingSenderId: '',
60+
projectId: demoProjectId,
61+
),
62+
);
63+
64+
return FirebaseApp._(app);
65+
}
4366
FirebaseAppPlatform app = await _delegate.initializeApp(
4467
name: name,
4568
options: options,

‎packages/firebase_core/firebase_core_platform_interface/lib/src/method_channel/method_channel_firebase.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class MethodChannelFirebase extends FirebasePlatform {
124124
// check to see if options are roughly identical (so we don't unnecessarily
125125
// throw on minor differences such as platform specific keys missing
126126
// e.g. hot reloads/restarts).
127-
if (defaultApp != null && _options != null) {
127+
if (defaultApp != null &&
128+
_options != null &&
129+
!_options.projectId.startsWith('demo-')) {
128130
if (_options.apiKey != defaultApp.options.apiKey ||
129131
(_options.databaseURL != null &&
130132
_options.databaseURL != defaultApp.options.databaseURL) ||

0 commit comments

Comments
 (0)
Please sign in to comment.