Form field
A form field puts a label, instructions and validation beside one input. Keep the instructions close enough to read while correcting an entry.
Name a project
#Type a one-letter project name to see the validation message. Add a second letter to clear it.
components/form-field/appliance/name_project.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class NameProject extends StatefulWidget {
const NameProject({super.key});
@override
State<NameProject> createState() => _NameProjectState();
}
class _NameProjectState extends State<NameProject> {
bool tooShort = false;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: SingleChildScrollView(
child: ApplianceField(
labelText: 'Project name',
helperText: 'For example, Field notes.',
errorText: tooShort ? 'Use at least two letters.' : null,
child: ApplianceTextField(
onChanged: (value) =>
setState(() => tooShort = value.trim().length == 1),
),
),
),
);
}
Parameters
ApplianceField API ↗labelText- Visible name for the entry.
helperText- Instruction displayed beside the entry.
errorText- Validation message for a one-letter project name.
Shared behaviour
- Keyboard and focus. Tab into the name field, type and edit without leaving the field. Focus stays with the entry as the validation message changes.
- Screen readers. Read the label and help, then inspect the message after entering one letter.
- Direction and type. Check how the help and validation text wrap at phone width and 200% text. Switch to RTL to find the start of the field.