flutter_checklist

Pub Version

A widget to display a checklist.

Screen recording of the example app

Installing

See the installing instructions.

Features

  • 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

Usage

ChecklistLine

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.

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.

The list of ChecklistLine is only read when the widget is created. To reset the checklist with other lines, also give it a new key.

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.

To still allow toggling the lines of a read only checklist, for example in a reading mode, also set the toggleable parameter to true: the lines can be checked and unchecked, but not edited, removed, added or reordered.

To also allow reordering the lines of a read only checklist, set the reorderable parameter to true: the lines can be dragged to another position, but not edited, removed or added. It can be combined with toggleable.

// 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
,
);

Localization

Embedded

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.

Custom

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(
)
,
)

Example

See the example app.