Skip to content

Commit

Permalink
feat(firebase_core_platform_interface): Add copyWith to FirebaseOptio…
Browse files Browse the repository at this point in the history
…ns (#13084)

* Add copyWith to FirebaseOptions

* Add test
  • Loading branch information
Rexios80 authored Jul 19, 2024
1 parent 806c15d commit c7963d6
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ class FirebaseOptions {
iosBundleId = options.iosBundleId,
appGroupId = options.appGroupId;

/// Returns a copy of this FirebaseOptions with the given fields replaced with
/// the new values.
FirebaseOptions copyWith({
String? apiKey,
String? appId,
String? messagingSenderId,
String? projectId,
String? authDomain,
String? databaseURL,
String? storageBucket,
String? measurementId,
String? trackingId,
String? deepLinkURLScheme,
String? androidClientId,
String? iosClientId,
String? iosBundleId,
String? appGroupId,
}) {
return FirebaseOptions(
apiKey: apiKey ?? this.apiKey,
appId: appId ?? this.appId,
messagingSenderId: messagingSenderId ?? this.messagingSenderId,
projectId: projectId ?? this.projectId,
authDomain: authDomain ?? this.authDomain,
databaseURL: databaseURL ?? this.databaseURL,
storageBucket: storageBucket ?? this.storageBucket,
measurementId: measurementId ?? this.measurementId,
trackingId: trackingId ?? this.trackingId,
deepLinkURLScheme: deepLinkURLScheme ?? this.deepLinkURLScheme,
androidClientId: androidClientId ?? this.androidClientId,
iosClientId: iosClientId ?? this.iosClientId,
iosBundleId: iosBundleId ?? this.iosBundleId,
appGroupId: appGroupId ?? this.appGroupId,
);
}

/// An API key used for authenticating requests from your app to Google
/// servers.
final String apiKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,52 @@ void main() {
expect(options1 == options2, isTrue);
});

test('should copyWith new values', () {
const options = FirebaseOptions(
apiKey: 'apiKey',
appId: 'appId',
messagingSenderId: 'messagingSenderId',
projectId: 'projectId',
);

final newOptions = options.copyWith(
apiKey: 'newApiKey',
appId: 'newAppId',
messagingSenderId: 'newMessagingSenderId',
projectId: 'newProjectId',
authDomain: 'newAuthDomain',
databaseURL: 'newDatabaseURL',
storageBucket: 'newStorageBucket',
measurementId: 'newMeasurementId',
trackingId: 'newTrackingId',
deepLinkURLScheme: 'newDeepLinkURLScheme',
androidClientId: 'newAndroidClientId',
iosClientId: 'newIosClientId',
iosBundleId: 'newIosBundleId',
appGroupId: 'newAppGroupId',
);

expect(
newOptions,
const FirebaseOptions(
apiKey: 'newApiKey',
appId: 'newAppId',
messagingSenderId: 'newMessagingSenderId',
projectId: 'newProjectId',
authDomain: 'newAuthDomain',
databaseURL: 'newDatabaseURL',
storageBucket: 'newStorageBucket',
measurementId: 'newMeasurementId',
trackingId: 'newTrackingId',
deepLinkURLScheme: 'newDeepLinkURLScheme',
androidClientId: 'newAndroidClientId',
iosClientId: 'newIosClientId',
iosBundleId: 'newIosBundleId',
appGroupId: 'newAppGroupId',
),
);
});

test('should return a Map', () {
const options = FirebaseOptions(
apiKey: 'apiKey',
Expand Down

0 comments on commit c7963d6

Please sign in to comment.