Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 11 additions & 2 deletions packages/rfw/lib/src/flutter/core_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// This file is hand-formatted.

// ignore: unnecessary_import, see https://github.com/flutter/flutter/pull/138881
import 'dart:ui' show FontFeature;

import 'package:flutter/gestures.dart' show DragStartBehavior;
Expand All @@ -28,6 +27,7 @@ import 'runtime.dart';
/// * [AspectRatio]
/// * [Center]
/// * [ColoredBox]
/// * [ClipRRect]
/// * [Column]
/// * [Container] (actually uses [AnimatedContainer])
/// * [DefaultTextStyle]
Expand Down Expand Up @@ -269,6 +269,15 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
);
},

'ClipRRect': (BuildContext context, DataSource source) {
// not implemented: clipper
return ClipRRect(
borderRadius: ArgumentDecoders.borderRadius(source, ['borderRadius']) ?? BorderRadius.zero,
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 +680,4 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
);
},

};
};
45 changes: 44 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,9 @@ import 'runtime.dart';
/// * The [Scaffold]'s floating action button position and animation features
/// are not supported.
///
/// * [DropdownButton] takes a list of items object with the key of params
/// names and value of the param values to represent [DropdownMenuItem].
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure exactly what this is trying to say but it doesn't seem to match the code — it seems to be a list of objects, and in each object there's zero or more of onTap, value, enabled, alignment, and child? (Not sure which are required and which are optional, but we should document that too.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment.

///
/// 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 +192,45 @@ Map<String, LocalWidgetBuilder> get _materialWidgetsDefinitions => <String, Loca
);
},

'DropdownButton': (BuildContext context, DataSource source) {
final length = source.length(['items']);
final dropdownMenuItems = List<DropdownMenuItem<Object>>.generate(
length,
(i) => DropdownMenuItem<Object>(
Copy link
Contributor

Choose a reason for hiding this comment

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

might be clearer if i was called index or some such
also, missing type ((int index))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

onTap: source.voidHandler(['items', i, 'onTap']),
value: source.v<String>(['items', i, 'value']),
Copy link
Contributor

Choose a reason for hiding this comment

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

does it matter that this has to be a string, given that the "current" value can be a string, int, double, or bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. This can be any given type. Fixed.

enabled: source.v<bool>(['items', i, 'enabled']) ?? true,
alignment: ArgumentDecoders.alignment(source, ['items', i, 'alignment']) ?? AlignmentDirectional.centerStart,
child: source.child(['items', i, 'child'])));

return DropdownButton<Object>(
items: dropdownMenuItems,
value: source.v<String>(['value']) ?? source.v<int>(['value']) ?? source.v<double>(['value']) ?? source.v<bool>(['value']),
hint: source.optionalChild(['hint']),
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 +389,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.
39 changes: 37 additions & 2 deletions packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ void main() {
),
),
),
Divider(),
Padding(
padding: [20.0],
child: Center(
child: DropdownButton(
value: 'foo',
items: [
{
value: 'foo',
child: Text(text: 'foo'),
onTap: event 'menu_item' {},
},
{
value: 'bar',
child: Text(text: 'bar'),
onTap: event 'menu_item' {},
},
],
onChanged: event 'dropdown' {},
),
),
),
],
),
floatingActionButton: FloatingActionButton(
Expand All @@ -135,15 +157,28 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.scaffold.png'),
skip: !runGoldens,
// skip: !runGoldens,
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to uncomment this out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Uncommented.

);

await tester.tap(find.byType(DropdownButton<Object>));
await tester.pumpAndSettle();
expect(find.text('bar'), findsOneWidget);
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('goldens/material_test.dropdown.png'),
// skip: !runGoldens,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

);
// Dismiss dropdown.
await tester.tapAt(Offset.zero);
await tester.pumpAndSettle();

await tester.tapAt(const Offset(20.0, 20.0));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.drawer.png'),
skip: !runGoldens,
// skip: !runGoldens,
);
});
}