From 7504c44556420d29279985ae8beb82f8056ed68c Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Fri, 21 Nov 2025 13:20:30 +0000 Subject: [PATCH 1/2] fix(database, Android): resolve limit modifier type casting --- .../plugins/firebase/database/FirebaseDatabasePlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firebase_database/firebase_database/android/src/main/kotlin/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.kt b/packages/firebase_database/firebase_database/android/src/main/kotlin/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.kt index 13582632b41f..dfc2b328b4f5 100644 --- a/packages/firebase_database/firebase_database/android/src/main/kotlin/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.kt +++ b/packages/firebase_database/firebase_database/android/src/main/kotlin/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.kt @@ -939,11 +939,11 @@ class FirebaseDatabasePlugin : "limit" -> { when (modifier["name"] as String) { "limitToFirst" -> { - val value = modifier["limit"] as Int + val value = (modifier["limit"] as Number).toInt() query = query.limitToFirst(value) } "limitToLast" -> { - val value = modifier["limit"] as Int + val value = (modifier["limit"] as Number).toInt() query = query.limitToLast(value) } } From 59a387e1f26523525399ac045d5a70cf9eda09ee Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Mon, 24 Nov 2025 09:38:45 +0000 Subject: [PATCH 2/2] test: add tests for limitToFirst and limitToLast stream emissions --- .../firebase_database/query_e2e.dart | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/integration_test/firebase_database/query_e2e.dart b/tests/integration_test/firebase_database/query_e2e.dart index fac8a1379f4e..23b0c1536757 100644 --- a/tests/integration_test/firebase_database/query_e2e.dart +++ b/tests/integration_test/firebase_database/query_e2e.dart @@ -226,6 +226,24 @@ void setupQueryTests() { expect(snapshot.value, isNull); }); + + test('streams emit limited maps', () async { + await ref.set({ + 'a': 'foo', + 'b': 'bar', + 'c': 'baz', + }); + + final event = await ref.orderByKey().limitToFirst(2).onValue.first; + + expect( + event.snapshot.value, + equals({ + 'a': 'foo', + 'b': 'bar', + }), + ); + }); }); group('limitToLast', () { @@ -266,6 +284,24 @@ void setupQueryTests() { expect(snapshot.value, isNull); }); + + test('streams emit limited maps', () async { + await ref.set({ + 'a': 'foo', + 'b': 'bar', + 'c': 'baz', + }); + + final event = await ref.orderByKey().limitToLast(2).onValue.first; + + expect( + event.snapshot.value, + equals({ + 'b': 'bar', + 'c': 'baz', + }), + ); + }); }); group('orderByChild', () {