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

[Property Editor] Add type info and have all inputs use fixed font #8791

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ class _PropertyInputState extends State<_PropertyInput> {

@override
Widget build(BuildContext context) {
// TODO(elliette): Refactor to split each argument type into its own input
// widget class for readability.
final theme = Theme.of(context);
final argument = widget.argument;
final decoration = InputDecoration(
helperText: argument.isRequired ? '*required' : '',
errorText: argument.errorText,
isDense: true,
label: Text('${argument.name}${argument.isRequired ? '*' : ''}'),
label: _inputLabel(argument, theme: theme),
border: const OutlineInputBorder(),
);
final argType = widget.argument.type;
Expand All @@ -179,7 +182,7 @@ class _PropertyInputState extends State<_PropertyInput> {
value: option,
// TODO(https://github.com/flutter/devtools/issues/8531) Handle onTap.
onTap: () {},
child: Text(option),
child: Text(option, style: theme.fixedFontStyle),
);
}).toList(),
onChanged: (newValue) async {
Expand Down Expand Up @@ -214,6 +217,54 @@ class _PropertyInputState extends State<_PropertyInput> {
}
}

Widget _inputLabel(EditableArgument argument, {required ThemeData theme}) {
final type = _typeForLabel(argument);
return RichText(
overflow: TextOverflow.ellipsis,
text: TextSpan(
text: type != null ? '$type ' : ':',
style: theme.fixedFontStyle,
children: [
TextSpan(
text: argument.name,
style: theme.fixedFontStyle.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
children: [
TextSpan(
text: argument.isRequired ? '*' : '',
style: theme.fixedFontStyle,
),
],
),
],
),
);
}

String? _typeForLabel(EditableArgument argument) {
String? typeName;
switch (argument.type) {
case 'string':
typeName = 'String';
break;
case 'int':
case 'double':
case 'bool':
typeName = argument.type;
break;
case 'enum':
typeName = argument.options?.first.split('.').first;
break;
default:
break;
}

if (typeName == null) return null;
return argument.isNullable ? '$typeName?' : typeName;
}

Future<void> _editArgument(String? valueAsString) async {
final argName = widget.argument.name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ void main() {
controller.initForTestsOnly(editableArgs: result1.args);
await tester.pumpAndSettle();

final titleInput = _findTextFormField('title');
final widthInput = _findTextFormField('width');
final heightInput = _findTextFormField('height');
final titleInput = _findTextFormField('String? title');
final widthInput = _findTextFormField('double width');
final heightInput = _findTextFormField('double? height');

// Verify the inputs are expected.
expect(_findNoPropertiesMessage, findsNothing);
Expand Down Expand Up @@ -169,8 +169,8 @@ void main() {
controller.initForTestsOnly(editableArgs: result2.args);
await tester.pumpAndSettle();

final softWrapInput = _findDropdownButtonFormField('softWrap');
final alignInput = _findDropdownButtonFormField('align');
final softWrapInput = _findDropdownButtonFormField('bool softWrap');
final alignInput = _findDropdownButtonFormField('Alignment? align');

// Verify the inputs are expected.
expect(_findNoPropertiesMessage, findsNothing);
Expand Down Expand Up @@ -422,7 +422,7 @@ final _findNoPropertiesMessage = find.text(
);

Finder _findTextFormField(String inputName) => find.ancestor(
of: find.textContaining(inputName),
of: find.richTextContaining(inputName),
matching: find.byType(TextFormField),
);

Expand All @@ -444,7 +444,7 @@ Finder _helperTextForInput(Finder inputFinder, {required String matching}) {
}

Finder _findDropdownButtonFormField(String inputName) => find.ancestor(
of: find.text(inputName),
of: find.richTextContaining(inputName),
matching: find.byType(DropdownButtonFormField<String>),
);

Expand Down
Loading