簡體   English   中英

Flutter 我在我的待辦事項列表應用程序中收到此錯誤

[英]I am getting this error in my Todo List App by Flutter

大家好,我正在 Flutter 制作一個 Todo 列表應用程序,我創建了一個名為“checkBoxCallBack”的 void function,並想在 Checkbox onChanged 屬性中使用它,我得到了這個我寫下的錯誤,我由 angela yu 訓練

錯誤:

Closure call with mismatched arguments: function '_TaskTileState.checkBoxCallBack'
Receiver: Closure: (bool) => void from Function 'checkBoxCallBack':.
Tried calling: _TaskTileState.checkBoxCallBack()
Found: _TaskTileState.checkBoxCallBack(bool) => void

我的代碼是:

class TaskTile extends StatefulWidget {
  const TaskTile({
    Key? key,
  }) : super(key: key);

  @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: checkBoxCallBack,
      ),
    );
  }
}

class TaskCheckBox extends StatelessWidget {
  final bool checkBoxState;
  final Function toggleCheckboxState;
  TaskCheckBox(
      {required this.checkBoxState, required this.toggleCheckboxState});
  @override
  Widget build(BuildContext context) {
    return Checkbox(
      value: checkBoxState,
      onChanged: toggleCheckboxState(),
    );
  }
}

    }

我發現了我的問題

這是固定代碼:

Checkbox(
      value: checkBoxState,
      onChanged: (bool? value) => toggleCheckboxState(value!),
    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM