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
4 changes: 4 additions & 0 deletions packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.3

* Coerces `int` and `double` values to `String` in the core `Text` widget adapter for both direct and list-based `text` values.

## 1.1.2

* Removes outdated call for feedback from the README.
Expand Down
10 changes: 9 additions & 1 deletion packages/rfw/lib/src/flutter/core_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,19 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid

'Text': (BuildContext context, DataSource source) {
String? text = source.v<String>(['text']);
text ??= source.v<int>(['text'])?.toString();
text ??= source.v<double>(['text'])?.toString();
if (text == null) {
final builder = StringBuffer();
final int count = source.length(['text']);
for (var index = 0; index < count; index += 1) {
builder.write(source.v<String>(['text', index]) ?? '');
final List<Object> key = <Object>['text', index];
String? segment = source.v<String>(key);
segment ??= source.v<int>(key)?.toString();
segment ??= source.v<double>(key)?.toString();
if (segment != null) {
builder.write(segment);
}
}
text = builder.toString();
}
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.1.2
version: 1.1.3

environment:
sdk: ^3.9.0
Expand Down
43 changes: 43 additions & 0 deletions packages/rfw/test/core_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,47 @@ void main() {
expect(flexibleWidgets[2].flex, equals(1));
expect(flexibleWidgets[2].fit, equals(FlexFit.loose));
});

testWidgets('Text renders numeric dynamic values', (WidgetTester tester) async {
final runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final data = DynamicContent()
..update('singleInt', 42)
..update('left', 67)
..update('right', 69)
..update('singleDouble', 13.37)
..update('leftDouble', -9000.01)
..update('rightDouble', 9000.01);

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
widget root = Directionality(
textDirection: "ltr",
child: Column(
crossAxisAlignment: "start",
children: [
Text(text: data.singleInt),
Text(text: [data.left, " / ", data.right]),
Text(text: data.singleDouble),
Text(text: [data.leftDouble, " / ", data.rightDouble]),
],
),
);
'''));

await tester.pumpWidget(
RemoteWidget(
runtime: runtime,
data: data,
widget: const FullyQualifiedWidgetName(LibraryName(<String>['test']), 'root'),
),
);
await tester.pump();

expect(find.text('42'), findsOneWidget);
expect(find.text('67 / 69'), findsOneWidget);
expect(find.text('13.37'), findsOneWidget);
expect(find.text('-9000.01 / 9000.01'), findsOneWidget);
});
}