Skip to content

Add rfw widgets #5661

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

Merged
merged 31 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2599faa
add rfw widgets
peixinli Dec 13, 2023
2fee2ad
add changelog
peixinli Dec 13, 2023
ba01940
revert format change
peixinli Dec 22, 2023
77b49b9
add tests
peixinli Dec 26, 2023
61bd40d
add golden file
peixinli Dec 26, 2023
9518814
uncomment runGoldens line
peixinli Dec 26, 2023
de5232c
Fix comments and add more test
peixinli Dec 27, 2023
e3248a6
Fix comments
peixinli Dec 27, 2023
06b3677
test value type
peixinli Dec 27, 2023
d5bcb37
Merge branch 'main' into rfw
peixinli Jan 2, 2024
5f031e1
add rfw widgets
peixinli Dec 13, 2023
ad6f552
add changelog
peixinli Dec 13, 2023
74c6c81
revert format change
peixinli Dec 22, 2023
9d00cea
add tests
peixinli Dec 26, 2023
7f8f5f2
add golden file
peixinli Dec 26, 2023
5976859
uncomment runGoldens line
peixinli Dec 26, 2023
d67a477
Fix comments and add more test
peixinli Dec 27, 2023
456a887
Fix comments
peixinli Dec 27, 2023
2ec30a2
test value type
peixinli Dec 27, 2023
a345557
Merge branch 'flutter:main' into rfw
peixinli Jan 6, 2024
7ac2967
fix comments
peixinli Jan 17, 2024
a23eeb1
Merge branch 'flutter:main' into rfw
peixinli Jan 17, 2024
751aedc
Merge branch 'rfw' of https://github.com/peixinli/packages into rfw
peixinli Jan 17, 2024
a92cfcd
fix comments
peixinli Jan 17, 2024
372e27f
merge main
peixinli Jan 24, 2024
32b8312
add line
peixinli Jan 24, 2024
43352e7
fix golden
peixinli Jan 24, 2024
53a8a5b
fix web
peixinli Jan 24, 2024
1f1db46
fix
peixinli Jan 24, 2024
16d1253
fix
peixinli Jan 24, 2024
e097047
fix
peixinli Jan 24, 2024
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: 3 additions & 1 deletion packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.0.18
## 1.0.19
* Add `DropdownButton` and `ClipRRect` widgets to rfw widget library.

## 1.0.18
* Exposes `WidgetLibrary`s registered in `Runtime`.
* Exposes widgets map in `LocalWidgetLibrary`.

Expand Down
10 changes: 10 additions & 0 deletions packages/rfw/lib/src/flutter/core_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'runtime.dart';
/// * [Align]
/// * [AspectRatio]
/// * [Center]
/// * [ClipRRect]
/// * [ColoredBox]
/// * [Column]
/// * [Container] (actually uses [AnimatedContainer])
Expand Down Expand Up @@ -269,6 +270,15 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
);
},

'ClipRRect': (BuildContext context, DataSource source) {
return ClipRRect(
borderRadius: ArgumentDecoders.borderRadius(source, ['borderRadius']) ?? BorderRadius.zero,
// CustomClipper<RRect> clipper,
clipBehavior: ArgumentDecoders.enumValue<Clip>(Clip.values, source, ['clipBehavior']) ?? Clip.antiAlias,
child: source.optionalChild(['child']),
);
},

'ColoredBox': (BuildContext context, DataSource source) {
return ColoredBox(
color: ArgumentDecoders.color(source, ['color']) ?? const Color(0xFF000000),
Expand Down
46 changes: 46 additions & 0 deletions packages/rfw/lib/src/flutter/material_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'runtime.dart';
/// * [CircularProgressIndicator]
/// * [Divider]
/// * [DrawerHeader]
/// * [DropdownButton]
/// * [ElevatedButton]
/// * [FloatingActionButton]
/// * [InkWell]
Expand Down Expand Up @@ -67,6 +68,11 @@ import 'runtime.dart';
/// * The [Scaffold]'s floating action button position and animation features
/// are not supported.
///
/// * [DropdownButton] takes a `items` object which contains a list of
/// [DropdownMenuItem] configuration objects. Each object may contain
/// `onTap`, `value`, `enabled` and `child`. The `child` parameter is
/// required.
///
/// In general, the trend will all of these unsupported features is that this
/// library doesn't support features that can't be trivially expressed using the
/// JSON-like structures of RFW. For example, [MaterialStateProperty] is
Expand Down Expand Up @@ -188,6 +194,46 @@ Map<String, LocalWidgetBuilder> get _materialWidgetsDefinitions => <String, Loca
);
},

'DropdownButton': (BuildContext context, DataSource source) {
final int length = source.length(['items']);
final List<DropdownMenuItem<Object>> dropdownMenuItems = List<DropdownMenuItem<Object>>.generate(
length,
(int index) => DropdownMenuItem<Object>(
onTap: source.voidHandler(['items', index, 'onTap']),
value: source.v<String>(['items', index, 'value']) ?? source.v<int>(['items', index, 'value']) ?? source.v<double>(['items', index, 'value']) ?? source.v<bool>(['items', index, 'value']),
enabled: source.v<bool>(['items', index, 'enabled']) ?? true,
alignment: ArgumentDecoders.alignment(source, ['items', index, 'alignment']) ?? AlignmentDirectional.centerStart,
child: source.child(['items', index, 'child']),
),
);

return DropdownButton<Object>(
items: dropdownMenuItems,
value: source.v<String>(['value']) ?? source.v<int>(['value']) ?? source.v<double>(['value']) ?? source.v<bool>(['value']),
disabledHint: source.optionalChild(['disabledHint']),
onChanged: source.handler(<Object>['onChanged'], (HandlerTrigger trigger) => (Object? value) => trigger(<String, Object?>{'value': value})),
onTap: source.voidHandler(['onTap']),
elevation: source.v<int>(['elevation']) ?? 8,
style: ArgumentDecoders.textStyle(source, ['style']),
underline: source.optionalChild(['underline']),
icon: source.optionalChild(['icon']),
iconDisabledColor: ArgumentDecoders.color(source, ['iconDisabledColor']),
iconEnabledColor: ArgumentDecoders.color(source, ['iconEnabledColor']),
iconSize: source.v<double>(['iconSize']) ?? 24.0,
isDense: source.v<bool>(['isDense']) ?? false,
isExpanded: source.v<bool>(['isExpanded']) ?? false,
itemHeight: source.v<double>(['itemHeight']) ?? kMinInteractiveDimension,
focusColor: ArgumentDecoders.color(source, ['focusColor']),
autofocus: source.v<bool>(['autofocus']) ?? false,
dropdownColor: ArgumentDecoders.color(source, ['dropdownColor']),
menuMaxHeight: source.v<double>(['menuMaxHeight']),
enableFeedback: source.v<bool>(['enableFeedback']),
alignment: ArgumentDecoders.alignment(source, ['alignment']) ?? AlignmentDirectional.centerStart,
borderRadius: ArgumentDecoders.borderRadius(source, ['borderRadius'])?.resolve(Directionality.of(context)),
padding: ArgumentDecoders.edgeInsets(source, ['padding']),
);
},

'ElevatedButton': (BuildContext context, DataSource source) {
// not implemented: buttonStyle, focusNode
return ElevatedButton(
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.18
version: 1.0.19

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
11 changes: 11 additions & 0 deletions packages/rfw/test/core_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rfw/formats.dart' show parseLibraryFile;
import 'package:rfw/rfw.dart';
Expand Down Expand Up @@ -278,5 +279,15 @@ void main() {
'''));
await tester.pump();
expect(find.byType(Wrap), findsOneWidget);

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
widget root = ClipRRect();
'''));
await tester.pump();
expect(find.byType(ClipRRect), findsOneWidget);
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
expect(renderClip.clipBehavior, equals(Clip.antiAlias));
expect(renderClip.borderRadius, equals(BorderRadius.zero));
});
}
Binary file modified packages/rfw/test/goldens/material_test.drawer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/rfw/test/goldens/material_test.scaffold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rfw/formats.dart' show parseLibraryFile;
Expand Down Expand Up @@ -123,6 +124,55 @@ void main() {
),
),
),
Divider(),
Padding(
padding: [20.0],
child: Row(
mainAxisAlignment: 'spaceEvenly',
children: [
DropdownButton(
value: 'foo',
elevation: 14,
dropdownColor: 0xFF9E9E9E,
underline: Container(
height: 2,
color: 0xFF7C4DFF,
),
style: {
color:0xFF7C4DFF,
},
items: [
{
value: 'foo',
child: Text(text: 'foo'),
},
{
value: 'bar',
child: Text(text: 'bar'),
onTap: event 'menu_item' { args: 'bar' },
},
],
borderRadius:[{x: 8.0, y: 8.0}, {x: 8.0, y: 8.0}, {x: 8.0, y: 8.0}, {x: 8.0, y: 8.0}],
onChanged: event 'dropdown' {},
),
DropdownButton(
value: 1.0,
items: [
{
value: 1.0,
child: Text(text: 'first'),
},
{
value: 2.0,
child: Text(text: 'second'),
onTap: event 'menu_item' { args: 'second' },
},
],
onChanged: event 'dropdown' {},
),
],
),
),
],
),
floatingActionButton: FloatingActionButton(
Expand All @@ -137,6 +187,28 @@ void main() {
matchesGoldenFile('goldens/material_test.scaffold.png'),
skip: !runGoldens,
);

await tester.tap(find.byType(DropdownButton<Object>).first);
await tester.pumpAndSettle();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('goldens/material_test.dropdown.png'),
skip: !runGoldens,
);
// Tap on the second item.
await tester.tap(find.text('bar'));
await tester.pumpAndSettle();
expect(eventLog, contains('menu_item {args: bar}'));
expect(eventLog, contains('dropdown {value: bar}'));

await tester.tap(find.byType(DropdownButton<Object>).last);
await tester.pumpAndSettle();
await tester.tap(find.text('second'));
await tester.pumpAndSettle();
expect(eventLog, contains('menu_item {args: second}'));
expect(eventLog,
contains(kIsWeb ? 'dropdown {value: 2}' : 'dropdown {value: 2.0}'));

await tester.tapAt(const Offset(20.0, 20.0));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
Expand Down