简体   繁体   English

Flutter 我在我的待办事项列表应用程序中收到此错误

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

hey guys I am making a Todo list app in Flutter, I create a void function which called "checkBoxCallBack" and want to use it in a Checkbox onChanged property and i got this error that i wrote down, i trained by angela yu大家好,我正在 Flutter 制作一个 Todo 列表应用程序,我创建了一个名为“checkBoxCallBack”的 void function,并想在 Checkbox onChanged 属性中使用它,我得到了这个我写下的错误,我由 angela yu 训练

error:错误:

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

my code is:我的代码是:

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(),
    );
  }
}

    }

I found my problem我发现了我的问题

here is the fixed code:这是固定代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 flutter 应用程序时出现错误 - I am getting error while running my flutter app 我在运行我的应用程序时收到此 E/flutter (25055) 错误(Flutter,FireBase - I am getting this E/flutter (25055) error when I am running my App (Flutter , FireBase 我正在运行 flutter 应用程序并收到此错误 - I am running flutter app and getting this error 我在尝试将数据从云 Firestore 带到我的 flutter 应用程序时遇到此错误 - I am getting this error while am trying to bring data from cloud firestore to my flutter app 我是 Flutter 的新手,并试图用 Flutter Launcher Icons 更改我的应用程序图标并收到错误“错误:InvalidConfigException”我该如何解决这个问题? - I am new in flutter and trying to change my app icon with Flutter Launcher Icons and getting error 'ERROR: InvalidConfigException' how i can fix this? 我在 streambuilder [Flutter] 中的应用程序中因空错误调用了方法“[]” - I am getting The method '[]' was called on null error in my app in streambuilder [Flutter] 当我尝试运行我的 flutter 应用程序时,运行 gradle 时出现错误 - When i am trying to run my flutter app it getting an Error running gradle 在运行颤振应用程序时出现此错误 - while running the flutter app i am getting this error 为什么我在 iOS(颤振应用程序)中收到 Firebase AppCheck 错误 - Why am I getting a Firebase AppCheck error in iOS (Flutter app) 我在 flutter 中设置我的投资组合时收到此错误 - I am getting this error styling my portfolio in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM