-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add rfw widgets #5661
Changes from 5 commits
2599faa
2fee2ad
ba01940
77b49b9
61bd40d
9518814
de5232c
e3248a6
06b3677
d5bcb37
5f031e1
ad6f552
74c6c81
9d00cea
7f8f5f2
5976859
d67a477
456a887
2ec30a2
a345557
7ac2967
a23eeb1
751aedc
a92cfcd
372e27f
32b8312
43352e7
53a8a5b
1f1db46
16d1253
e097047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import 'runtime.dart'; | |
| /// * [CircularProgressIndicator] | ||
| /// * [Divider] | ||
| /// * [DrawerHeader] | ||
| /// * [DropdownButton] | ||
| /// * [ElevatedButton] | ||
| /// * [FloatingActionButton] | ||
| /// * [InkWell] | ||
|
|
@@ -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]. | ||
|
||
| /// | ||
| /// 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 | ||
|
|
@@ -188,6 +192,45 @@ Map<String, LocalWidgetBuilder> get _materialWidgetsDefinitions => <String, Loca | |
| ); | ||
| }, | ||
|
|
||
| 'DropdownButton': (BuildContext context, DataSource source) { | ||
| final length = source.length(['items']); | ||
peixinli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final dropdownMenuItems = List<DropdownMenuItem<Object>>.generate( | ||
peixinli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| length, | ||
| (i) => DropdownMenuItem<Object>( | ||
|
||
| onTap: source.voidHandler(['items', i, 'onTap']), | ||
| value: source.v<String>(['items', i, 'value']), | ||
|
||
| enabled: source.v<bool>(['items', i, 'enabled']) ?? true, | ||
| alignment: ArgumentDecoders.alignment(source, ['items', i, 'alignment']) ?? AlignmentDirectional.centerStart, | ||
| child: source.child(['items', i, 'child']))); | ||
peixinli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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( | ||
|
|
@@ -346,4 +389,4 @@ Map<String, LocalWidgetBuilder> get _materialWidgetsDefinitions => <String, Loca | |
| ); | ||
| }, | ||
|
|
||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' {}, | ||
| ), | ||
| ), | ||
| ), | ||
peixinli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], | ||
| ), | ||
| floatingActionButton: FloatingActionButton( | ||
|
|
@@ -135,15 +157,28 @@ void main() { | |
| await expectLater( | ||
| find.byType(RemoteWidget), | ||
| matchesGoldenFile('goldens/material_test.scaffold.png'), | ||
| skip: !runGoldens, | ||
| // skip: !runGoldens, | ||
|
||
| ); | ||
|
|
||
| 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, | ||
|
||
| ); | ||
| // 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, | ||
peixinli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
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?