Skip to content

Commit

Permalink
Add type info and have all inputs used fixed font (#8791)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Jan 22, 2025
1 parent 3a76256 commit 69c37ba
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,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 @@ -196,7 +199,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 @@ -231,6 +234,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 @@ -143,9 +143,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 @@ -175,8 +175,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 @@ -428,7 +428,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 @@ -450,7 +450,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

0 comments on commit 69c37ba

Please sign in to comment.