无法将参数类型“Function”分配给参数类型“void Function()?”

时间:2021-06-26 16:13:59

标签: flutter dart

import 'package:flutter/material.dart';

class Answers extends StatelessWidget {
  final Function nextQuestion;

  Answers(this.nextQuestion);

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: nextQuestion,
      child: Text("Answer"),    
    );
  }
}

1 个答案:

答案 0 :(得分:1)

只需将 nextQuestion 的类型更改为 void Function()

final void Function() nextQuestion;