Skip to content

Share/Unify Timestamp between google_cloud_firestore and cloud_firestore #286

Open

Description

@mafreud

Proposal: Share/Unify Timestamp between google_cloud_firestore and cloud_firestore

Problem

When building full-stack Dart applications (Flutter on the client, Dart VM/Firebase Functions on the server), sharing data models with Firestore timestamps is highly problematic.

  • cloud_firestore (specifically cloud_firestore_platform_interface) and google_cloud_firestore (firebase-admin-dart) define their own incompatible Timestamp classes.
  • Even though they have the same underlying structure (seconds and nanoseconds), Dart's static type system treats them as completely separate types.
  • As a result, shared models cannot run simple type checks (like value is Timestamp) without introducing Flutter dependencies to the backend. Developers must rely on brittle workarounds like string-based runtime type checking (value.runtimeType.toString().contains('Timestamp')).

Proposed Solution

We highly recommend extracting basic, pure Dart Firestore types (such as Timestamp and GeoPoint) into a lightweight, neutral package (e.g., firebase_common_types) with no dependencies on Flutter or VM-specific APIs.

Both cloud_firestore and google_cloud_firestore should then depend on and re-export these shared types. This will enable clean, type-safe full-stack Dart development.

Activity

  1. demolaf commented on Jun 4, 2026

    @demolaf
    Member

    Hi @mafreud , this does make a lot of sense. I will raise this with the team and keep this issue updated.

  2. mafreud commented on Jun 4, 2026

    @mafreud
    Author

    @demolaf Thank you as always!

  3. ChreSyr commented on Jun 24, 2026

    @ChreSyr

    I'm running into a similar issue with Timestamp.

    My Flutter app uses cloud_firestore to fetch documents containing Timestamp values. These documents are then passed to models defined in a separate package that is shared between the app and my Firebase Functions.

    That shared package cannot depend on cloud_firestore, since it is also used by the dart functions package, which doesn't support flutter packages. Instead, it depends on google_cloud_firestore and therefore expects google_cloud_firestore.Timestamp.

    As a result, my TimestampConverter (defined in the shared models package) cannot recognize the Timestamp instances returned by cloud_firestore, even though cloud_firestore depends on google_cloud_firestore.

    This makes me wonder: why doesn't cloud_firestore expose and use the Timestamp type from google_cloud_firestore directly?

    I've run into similar, although less impactful, issues with duplicated definitions of GeoPoint and Filter.

    @demolaf Is the team considering addressing this in the future? Shared model packages seem like a common use case now that Dart support for Firebase Functions is available.

  4. demolaf commented on Jun 25, 2026

    @demolaf
    Member

    @ChreSyr Yes, this has been raised internally. I'll try to provide feedback once I have more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions