Swipe actions
Swipe actions keep a contextual command beside the row it affects. Give the command a short verb and make its result easy to undo.
Archive a note
#Reveal Archive from the trailing side of the Route note row. Archive it and use Restore note to bring it back.
components/swipe-actions/appliance/archive_note.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ArchiveNote extends StatefulWidget {
const ArchiveNote({super.key});
@override
State<ArchiveNote> createState() => _ArchiveNoteState();
}
class _ArchiveNoteState extends State<ArchiveNote> {
bool archived = false;
bool read = false;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: archived
? ApplianceButton(
'Restore note',
onPressed: () => setState(() {
archived = false;
read = false;
}),
)
: ApplianceSwipeActions(
endActions: [
DesignSwipeAction(
label: 'Archive',
onPressed: () => setState(() => archived = true),
),
],
child: ApplianceListTile(
title: 'Route note',
subtitle: read ? 'Read' : 'Unread',
onTap: () => setState(() => read = !read),
),
),
);
}
Parameters
ApplianceSwipeActions API ↗child- The row.
startActions- The keys a swipe toward the end shows.
endActions- The keys a swipe toward the start shows.
Shared behaviour
- Keyboard and focus. Tab to the row. Where the look supports keyboard reveal, press the arrow toward the reading start to show Archive and Escape to close it. Material Expressive places an Archive note button after the row.
- Screen readers. Inspect the named actions on the row. Archiving replaces it with a restore button, which also identifies the result.
- Direction and type. Swipe toward the left in LTR and the right in RTL. Compare the revealed action at normal and large text sizes.