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) } } 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', () {