Pim Schwippert
Pim Schwippert

Reputation: 453

how do I use this OnCompleted function?

This library I found that handles music playing has the following variable public.

void Function() onCompleted;

I want to change the icon of a button when the track is finished, so that it returns to a play icon.

I tried using musicPlayer.OnCompleted(() { **stuff** }); but that gives me a syntax error Too many positional arguments: 0 expected, but 1 found.

How do I subscribe on that event, or how do I check if OnCompleted has been called?

I am still pretty new to dart but can't wrap my head around this one. I tried subscribing like in Angular or looking up if there's a different syntax for it, but I am at a loss.

Upvotes: 0

Views: 182

Answers (1)

Richard Heap
Richard Heap

Reputation: 51682

Presumably you have to set onCompleted to something, specifically a function taking no parameters and returning void.

It would be normal to provide something like this in the constructor. Is there a named, optional parameter for this? Alternatively, there may be a setter.

Let's assume there's a setter. You could write:

  musicPlayer.onCompleted = (){/* do stuff*/};

Upvotes: 2

Related Questions