Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,20 @@ void setupDataSnapshotTests() {
expect(children[1].value, 2);
expect(children[2].value, 3);
});

test('children returns the children for a nested list snapshot', () async {
final ref = getRef('nested-list-children');
await ref.set({
'items': ['first', 'second', 'third'],
});
final s = await ref.get();

final children = s.child('items').children.toList();
expect(children.map((c) => c.key).toList(), ['0', '1', '2']);
expect(
children.map((c) => c.value).toList(),
['first', 'second', 'third'],
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ List<String> _childKeysFromValue(Object? value) {
} else if (value is List) {
childChildKeys = List<String>.generate(
value.length,
(int index) => '${index - 1}',
(int index) => '$index',
);
}
return childChildKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database_platform_interface/firebase_database_platform_interface.dart';
import 'package:firebase_database_platform_interface/src/method_channel/method_channel_data_snapshot.dart';
import 'package:firebase_database_platform_interface/src/method_channel/method_channel_database.dart';
import 'package:firebase_database_platform_interface/src/method_channel/method_channel_database_reference.dart';
import 'package:firebase_database_platform_interface/src/pigeon/messages.pigeon.dart'
Expand Down Expand Up @@ -563,6 +564,33 @@ void main() {
);
});
});

group('MethodChannelDataSnapshot', () {
test(
'child() on a List-valued child generates 0-based childKeys and iterates children without RangeError',
() {
final snapshot = MethodChannelDataSnapshot(
database.ref('root'),
<String, dynamic>{
'key': 'root',
'value': <String, dynamic>{
'items': <Object?>['first', 'second', 'third'],
},
'priority': null,
'childKeys': <String>['items'],
},
);

final itemsSnapshot = snapshot.child('items');
final children = itemsSnapshot.children.toList();

expect(children.map((c) => c.key).toList(), <String>['0', '1', '2']);
expect(
children.map((c) => c.value).toList(),
<Object?>['first', 'second', 'third'],
);
});
});
});
}

Expand Down
Loading