I am trying to set the initial value of a boolean from a value passed into my widget. My attempt right now looks like:
const CustomLikeButton({
Key? key,
required this.liked,
}) : super(key: key);
final bool liked;
@override
State<CustomLikeButton> createState() => _CustomLikeButtonState();
}
class _CustomLikeButtonState extends State<CustomLikeButton> {
bool _liked;
@override
void initState() {
bool _liked = widget.liked;
super.initState();
}
but it is giving the error:
Non-nullable instance field '_liked' must be initialized.
Try adding an initializer expression, or a generative constructor that initializes it, or mark it 'late'.
Anyone know what is going wrong here?
Thank you!