【发布时间】:2021-09-01 07:12:46
【问题描述】:
问题是标题。我正在尝试构建 todoye 应用程序,正如您所看到的,回调被认为是 ValueChanged
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
_TaskTileState 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(
'finish up angla\'s course today',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null,
),
),
trailing: TaskCheckBox(
checkBoxState: isChecked,
toggleCheckBoxState: checkBoxCallBack,
),
);
}
}
class TaskCheckBox extends StatelessWidget {
final bool checkBoxState;
final ValueChanged<bool?> toggleCheckBoxState;
const TaskCheckBox({
required this.checkBoxState,
required this.toggleCheckBoxState,
});
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.lime,
value: checkBoxState,
onChanged: toggleCheckBoxState,
);
}
}
错误在第 27 行...我想将我的自定义函数传递给我的 statelessWidget 变量。
【问题讨论】: