A widget to display a checklist.
See the installing instructions.
- Display a checklist
- Toggle items and edit their text
- Reorder items
- Add new items (either after the submitted one or at the end)
- Remove items
- Make the checklist read only
The ChecklistLine
type is a record that represents a line (an item, an entry) of the checklist. It contains the text of that line and whether it is toggled.
A list of ChecklistLine
represents a checklist with all its lines. The order of the list directly determines the order of the items in the checklist.
The Checklist
widget displays your list of ChecklistLine
as a checklist.
It requires as arguments the list of ChecklistLine
to display, and a callback function to execute when any modification is performed on that list with the new list of ChecklistLine
.
A checklist can be made read only by setting the enabled
parameter to false
, which disables any modification to the checklist lines as well as their reordering.
// The list of five ChecklistLine to display with their text and whether they are toggled
final lines = List.generate(
5,
(index) => (text: 'Line ${index + 1}', toggled: false),
);
// The function to execute when the checklist is modified, with the new list of ChecklistLine
void onChanged(List<ChecklistLine> lines) {
log(lines.toString());
}
// The checklist widget
Checklist(
lines: lines,
onChanged: onChanged,
);
This package supports localization. To enable it in your app, add the localizations delegates to your MaterialApp
:
MaterialApp(
localizationsDelegates: [
ChecklistLocalizations.delegate,
// Any other localizations delegates, from your app or other packages
],
);
The following localizations are currently supported (ordered alphabetically):
- English
- French
To add support for a new localization or improve an existing one, please open an issue.
To provide your own localizations (to replace the embedded ones are provide missing ones), implement the ChecklistLocalizations
class (for examples, look at the generated ones) and pass it to the localizations
parameter:
Checklist(
lines: lines,
onChanged: onChanged,
localizations: CustomChecklistLocalizations(),
)
See the example app.