Skip to content

Commit

Permalink
Make widget builders work with loops
Browse files Browse the repository at this point in the history
  • Loading branch information
tugorez committed Feb 17, 2025
1 parent e9598f2 commit 5a54802
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/rfw/lib/src/flutter/runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ abstract class _CurriedWidget extends BlobNode {
);
} else if (inputList is DataReference) {
inputList = dataResolver(inputList.parts);
} else if (inputList is WidgetBuilderArgReference) {
inputList = widgetBuilderArgResolver(
<Object>[inputList.argumentName, ...inputList.parts],
);
} else if (inputList is BoundStateReference) {
inputList = stateResolver(inputList.parts, inputList.depth);
} else if (inputList is BoundLoopReference) {
Expand Down
48 changes: 48 additions & 0 deletions packages/rfw/test/runtime_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,54 @@ void main() {
expect(textFinder, findsOneWidget);
expect(tester.widget<Text>(textFinder).data, 'The input is true, the output is false');
});

testWidgets('Widget builders - builder works with loops', (WidgetTester tester) async {
const LibraryName coreLibraryName = LibraryName(<String>['core']);
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

runtime.update(coreLibraryName, createCoreWidgets());
runtime.update(
localLibraryName,
LocalWidgetLibrary(<String, LocalWidgetBuilder>{
'Builder': (BuildContext context, DataSource source) {
return source.builder(
<String>['builder'],
<String, Object?>{
'values': <String>['Value1', 'Value2', 'Value3'],
},
);
},
}));
runtime.update(remoteLibraryName, parseLibraryFile('''
import core;
import local;
widget test = Builder(
builder: (scope) =>
Column(
children: [
...for value in scope.values:
Text(text: value, textDirection: 'ltr'),
],
),
);
'''));
await tester.pumpWidget(RemoteWidget(
runtime: runtime,
data: data,
widget: const FullyQualifiedWidgetName(remoteLibraryName, 'test'),
));

expect(textFinder, findsNWidgets(3));
expect((textFinder.at(0).evaluate().first.widget as Text).data, 'Value1');
expect((textFinder.at(1).evaluate().first.widget as Text).data, 'Value2');
expect((textFinder.at(2).evaluate().first.widget as Text).data, 'Value3');
});
}

final class RfwEvent {
Expand Down

0 comments on commit 5a54802

Please sign in to comment.