Skip to content

[firebase_database]: Type Inconsistency: Integers are returned as double on Web WASM via SDK, but int via REST API #17986

@mcagrigoktas

Description

@mcagrigoktas

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Database

Which platforms are affected?

Web

Description

There is a significant type inconsistency when fetching data from Firebase Realtime Database on Flutter Web using the WASM target. When using the firebase_database SDK, all numeric values (even whole numbers) are returned as double. However, when fetching the same node via the Firebase REST API, the values are correctly identified as int.

This causes type 'double' is not a subtype of type 'int' errors at runtime on WASM, where type enforcement is stricter than on the JS target.

Reproducing the issue

Create a Firebase Realtime Database node with an integer: {"count": 42}.

Fetch this node using the firebase_database SDK on a Flutter Web app compiled with --wasm.

Check the type: data['count'].runtimeType returns double.

Fetch the same node using http.get via REST API.

Check the type: data['count'].runtimeType returns int.

Expected Behavior: The SDK should maintain type consistency where possible, or at least match the behavior of the JSON decoder used in REST/Native platforms, especially since WASM distinguishes strictly between int and double.

Actual Behavior:

SDK (WASM): Returns double (likely due to JS Number interop).

REST API (WASM): Returns int.

SDK (Native/Mobile): Returns int.

Target: Web (WASM)

Firebase Core version

4.4.0

Flutter Version

3.38.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions