Text area
Use a text area for a note that can span several lines. Give people room to see the surrounding sentences while they edit.
Write a note
#Write a delivery note. Press Enter to add another line and watch the line count change.
components/text-area/appliance/write_note.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class WriteNote extends StatefulWidget {
const WriteNote({super.key});
@override
State<WriteNote> createState() => _WriteNoteState();
}
class _WriteNoteState extends State<WriteNote> {
int lines = 0;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceTextField(
label: 'Delivery note',
minLines: 2,
maxLines: 3,
onChanged: (note) => setState(
() => lines = note.isEmpty ? 0 : note.split('\n').length,
),
),
const SizedBox(height: 12),
Text('Lines: $lines'),
],
),
);
}
Parameters
ApplianceTextField API ↗label- Name that stays with the note.
onChanged- Recounts the lines when the note changes.
minLines- Height of the empty editing area, in lines.
maxLines- Maximum visible lines before the text scrolls.
Shared behaviour
- Keyboard and focus. Tab into the note. Enter inserts a line break, and the arrow keys move the caret through the text.
- Screen readers. The editable field has the name “Delivery note”. The count below it includes the lines separated by Enter.
- Direction and type. The field uses the available width. Lines can wrap as the frame narrows or the type grows without changing the count.