Count badge
A count badge adds a short quantity to a named item. Keep the thing being counted close enough that the number has a meaning.
Read messages
#Begin with three unread messages. Mark one read to see the count fall, then reset the inbox when it is empty.
components/badge/appliance/read_messages.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ReadMessages extends StatefulWidget {
const ReadMessages({super.key});
@override
State<ReadMessages> createState() => _ReadMessagesState();
}
class _ReadMessagesState extends State<ReadMessages> {
int unread = 3;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Inbox'),
const SizedBox(height: 12),
ApplianceBadge('$unread'),
const SizedBox(height: 12),
ApplianceButton(
unread == 0 ? 'Reset inbox' : 'Mark one read',
onPressed: () =>
setState(() => unread = unread == 0 ? 3 : unread - 1),
),
],
),
);
}
Parameters
ApplianceBadge API ↗text- The figure.
style- Overrides the component’s themed appearance for this instance.
Shared behaviour
- Keyboard and focus. Tab to Mark one read and activate it repeatedly. Reset inbox restores the three messages.
- Screen readers. Read the inbox name, then its unread count. Look-specific badges can hide the mark at zero.
- Direction and type. The count stays with the inbox in RTL. Check the badge and its action at both text sizes.