Text field
Use a text field for a short, single-line answer such as the name of a draft. A visible label still identifies the field after someone starts typing.
Name a draft
#Type a title, then edit or erase it. The draft heading below follows your changes and returns to Untitled when the field is empty.
components/text-field/appliance/name_draft.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class NameDraft extends StatefulWidget {
const NameDraft({super.key});
@override
State<NameDraft> createState() => _NameDraftState();
}
class _NameDraftState extends State<NameDraft> {
String title = '';
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceTextField(
label: 'Draft title',
onChanged: (value) => setState(() => title = value.trim()),
),
const SizedBox(height: 12),
Text(
title.isEmpty ? 'Untitled' : title,
maxLines: 3,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
);
}
Parameters
ApplianceTextField API ↗label- Visible name of the editable field.
onChanged- Updates the draft heading after each edit.
Shared behaviour
- Keyboard and focus. Tab to the field and type. Use the arrows to move the caret and the usual editing shortcuts to select or replace text.
- Screen readers. The field is named “Draft title”. Its editable value and the resulting heading can be read separately.
- Direction and type. The label and the heading follow reading direction. Try a long title at 200% to see the heading wrap.