import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
State<TaskTile> createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked = false;
// void checkboxCallback(bool checkboxState) {
// setState(() {
// isChecked = checkboxState;
// });
// }
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
'This is a task.',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null),
),
trailing: TaskCheckbox(
checkboxState: isChecked,
toggleCheckboxState: (bool checkboxState) {
setState(() {
isChecked = checkboxState;
});
}),
);
}
}
class TaskCheckbox extends StatelessWidget {
final bool checkboxState;
final Function toggleCheckboxState;
const TaskCheckbox(
{required this.checkboxState, required this.toggleCheckboxState});
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.lightBlueAccent,
value: checkboxState,
onChanged: toggleCheckboxState(),
);
}
}
As per the concept of Global state. I'm trying to use my bool isChecked value for both checkbox and checkbox title which is text. But i get the blue blank in my android emulator. I'm new to flutter and don't know exactly what went wrong. Can anyone help me with this?