Quantcast
Viewing all articles
Browse latest Browse all 608

The argument type 'void Function(bool?, int) Function(bool?, dynamic)' can't be assigned to the parameter type 'dynamic Function(bool?)?'

I'm trying to learn Flutter and I'm developing Todo appBut I got stuck with a bugHere is my code

List view

body: ListView.builder(          itemCount: todos.length,          itemBuilder: (context, index) {            return Todo(                taskName: todos[index][0],                completed: todos[index][1],                onChanged: (value, index) => checkboxChanged); // here the index argument is causing the error          },        )

and the Todo class

class Todo extends StatelessWidget {  final String taskName;  final bool completed;  Function(bool?)? onChanged; // the method   Todo(      {super.key,      required this.taskName,      required this.completed,      required this.onChanged});  @override  Widget build(BuildContext context) {    return Padding(      padding: EdgeInsets.only(left: 10, top: 10, right: 10),      child: Container(          padding: EdgeInsets.all(20),          decoration: BoxDecoration(              color: Colors.yellow, borderRadius: BorderRadius.circular(10)),          child: Row(            children: [              Checkbox(                value: completed,                onChanged: onChanged,                activeColor: Colors.black,              ),              Text(taskName),            ],          )),    );  }}

There comes up when I add the index parameter here

  void checkboxChanged(bool? value, int index) { // if I remove the indext parameter from here and from the Todo instantiation in the ListView the error will be gone. but I need that way    setState(() {      todos[index][1] = !todos[index][1];    });  }

The error message I'm facing is

The argument type 'void Function(bool?, int) Function(bool?, dynamic)' can't be assigned to the parameter type 'dynamic Function(bool?)?'

Any help is appreciated.Thanks...


Viewing all articles
Browse latest Browse all 608

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>