Sometimes this can be tricky because the Text
widget might not be the one which is const
(where the error is displayed), but maybe its parent widget is const
or the parent of that parent widget, etc. In that case it could be surprising and not immediate to spot the solution. For example:
const PrefLabel(
title: Text(
preferenceOptionTitle,
style: Get.textTheme.headline5!,
maxLines: 3,
),
subtitle: Text(preferenceOptionDescription),
),
In this case the Text
is not marked with const
because the PrefLabel
is already const
. The corrected one which passes linting: const
is moved to the subtitle
PrefLabel(
title: Text(
preferenceOptionTitle,
style: Get.textTheme.headline5!,
maxLines: 3,
),
subtitle: const Text(preferenceOptionDescription),
),