Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function field return type in Dart

Tags:

flutter

dart

In the following class I want to type the onPress method as a function which returns void. Is there a way to do that?

class Human {
  var onPress;

  Human({
    this.onPress,
  });
}
like image 889
Babistalikesflyingonrails Avatar asked Dec 14 '25 08:12

Babistalikesflyingonrails


1 Answers

class Human {
  void Function() onPress;

  Human({
    this.onPress,
  });
}

or

typedef VoidFunction = void Function();

class Human {
  VoidFunction onPress;

  Human({
    this.onPress,
  });
}
like image 128
Rémi Rousselet Avatar answered Dec 15 '25 21:12

Rémi Rousselet