-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Needs AttentionThis issue needs maintainer attention.This issue needs maintainer attention.platform: allIssues / PRs which are for all platforms.Issues / PRs which are for all platforms.plugin: databasetype: bugSomething isn't workingSomething isn't working
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Database
Which platforms are affected?
iOS, macOS, Web, Windows, Android
Description
Actual behavior
When using a DocumentReference as a map field key and attempting to write that map field to a Firestore document, the SDK throws a type cast error:
type '_JsonDocumentReference' is not a subtype of type 'String' in type cast
Expected behavior
Since Firestore natively supports DocumentReference as map keys (this can be verified by manually adding a reference-type map key via the Firebase Console UI), the FlutterFire SDK should serialize DocumentReference keys the same way it handles DocumentReference values.
Reproducing the issue
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final firestore = FirebaseFirestore.instance;
final docRef = firestore.doc('testCollection/testDoc');
final Map<DocumentReference, double> doublePerRef = {
docRef: 100.0,
};
try {
await firestore.doc('testCollection/testDoc').set({
'doublePerRef': doublePerRef,
});
print('Success');
} catch (e) {
print('Error: $e');
// Error: type '_JsonDocumentReference' is not a subtype of type 'String' in type cast
}
}
Firebase Core version
3.15.2
Flutter Version
3.35.7
Relevant Log Output
Flutter dependencies
No response
Additional context and comments
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs AttentionThis issue needs maintainer attention.This issue needs maintainer attention.platform: allIssues / PRs which are for all platforms.Issues / PRs which are for all platforms.plugin: databasetype: bugSomething isn't workingSomething isn't working