How to generic a optional parameter in Dart/Flutter

Viewed 155

I have a problem when I try to make some interfaces and need to implement them with a generic. My question is how can I use a nothing type like

Nothing in Kotlin

Void in Java

Example:

I have a base class

abstract class Base<Out, In> {
  Future<Out> perform(In);
}

normal case I use, it perfect

class Download implements Base<bool, String> {

  @override
  Future<bool> perform(downloadUrl) async {
    // do download and return result here
  }
}

In some cases, I don't need to include any parameters. but it require 2 generic type so I have to include void as input

class DoSomething implements Base<bool, void> {

  @override
  Future<bool> perform(_) async {
    // do some thing here, no use the input parameter
  }
}

The problem is when call perform function in DoSomething class it treat void as type of function don't like as Java, it require a input parameter instead of nothing

DoSomething().perform((){});

I don't want to include any parameter in the perform function. Please give me any suggestions, solution to handle this case.

1 Answers

you can use

function({dynamic optional_parameter})

its an optional parameter you can simply ignore it if you dont want to process/use it and it will be null.

Related