每当我创建void函数时,不会调用无状态小部件的构建方法,因为也不会调用其他方法。请指导可能的解决方案。
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
_TaskTileState createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked= true;
void checkboxCallback (checkboxState){
setState(() {
isChecked=che ckboxState;
});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text('This is my task.',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null,
),),
trailing: TaskCheckBox(isChecked,checkBoxCallback),
);
}
}
class TaskCheckBox extends StatelessWidget {
final bool checkboxState;
final Function toggleCheckBoxState;
TaskCheckBox (this.checkboxState, this.toggleCheckBoxState);
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.blueAccent,
value: checkboxState,
onChanged:
});
}
}