Home > Blockchain >  The argument type 'void Function(int)' can't be assigned to the parameter type '
The argument type 'void Function(int)' can't be assigned to the parameter type '

Time:08-25

I'm exploring the language flutter and I encountered this error. Here is the answerQuestion function

void _answerQuestion(int score) {
  totalScore  = score;
  if (_questionIndex < _questions.length) {
    print("We have more qiestions");
  }
  setState(() {
    _questionIndex = _questionIndex   1;
  });

  print(_questionIndex);
}

The error

return MaterialApp(
  home: Scaffold(
      appBar: AppBar(
        title: Text('My first App'),
      ),
      body: _questionIndex < _questions.length
          ? Quiz(
              answerQuestion: _answerQuestion, //the error
              questions: _questions,
              questionIndex: _questionIndex,
            )
  
  

CodePudding user response:

Well, we don't know the interface of the Quiz class but seems like the answerQuestion argument is expecting a function of type void (), rather than void (int) like _answerQuestion.

If you were to provide a complete code sample, including the Quiz class, identifying the issue would be much easier.

CodePudding user response:

small change done your work

Function()? questions; --> Function(int)? questions;
  • Related