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

Add rfw widgets #5661

Merged
merged 31 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
1 change: 1 addition & 0 deletions packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
* Fixes lint warnings.
* Add one core widget and one material widget.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should say which ones :-)
remember the old trick when writing documentation: what question is someone trying to answer when reading your prose? what questions will they have after reading your prose?


## 1.0.15

Expand Down
12 changes: 11 additions & 1 deletion packages/rfw/lib/src/flutter/core_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'runtime.dart';
/// * [AspectRatio]
/// * [Center]
/// * [ColoredBox]
/// * [ClipRRect]
peixinli marked this conversation as resolved.
Show resolved Hide resolved
/// * [Column]
/// * [Container] (actually uses [AnimatedContainer])
/// * [DefaultTextStyle]
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,
// clipper,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the convention for skipped parameters in this file is to give the type as well (see line 441)

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 Expand Up @@ -671,4 +681,4 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
);
},

};
};
47 changes: 46 additions & 1 deletion 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,10 @@ import 'runtime.dart';
/// * The [Scaffold]'s floating action button position and animation features
/// are not supported.
///
/// * [DropdownButton] takes a list of objects representing the
peixinli marked this conversation as resolved.
Show resolved Hide resolved
/// [DropdownMenuItem]s. Each object may contain `onTap`, `value`, `enabled`
/// and `child`. The `child` param is required.
peixinli marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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 +193,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 Expand Up @@ -346,4 +391,4 @@ Map<String, LocalWidgetBuilder> get _materialWidgetsDefinitions => <String, Loca
);
},

};
};
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.
70 changes: 70 additions & 0 deletions packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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' {},
),
],
),
),
peixinli marked this conversation as resolved.
Show resolved Hide resolved
],
),
floatingActionButton: FloatingActionButton(
Expand All @@ -137,6 +186,27 @@ 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('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