Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rfw] Make widget builders work with loops #8650

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 1.0.31

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Fixes an issue where Widget Builders didn't work properly with Loops.

## 1.0.30

Expand Down
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
2 changes: 1 addition & 1 deletion packages/rfw/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: rfw
description: "Remote Flutter widgets: a library for rendering declarative widget description files at runtime."
repository: https://github.com/flutter/packages/tree/main/packages/rfw
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+rfw%22
version: 1.0.30
version: 1.0.31

environment:
sdk: ^3.4.0
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