2017-06-03 31 views
0

我有这个功能,在Flutter内使用audioplayer plugin播放声音。Dart - 玩一圈期货

play(int soundFrequency) async { 
    final result = await audioPlayer.play("urltosound.wav"); 
} 

它工作正常。但现在我希望能够连续播放多个声音。看起来好像我搞砸了期货。我试过这种方法,这是非常肮脏和丑陋,但我只是想搞清楚这些事情:

playRandomSequence() async { 
    final result = audioPlayer.play("urltosound.wav").then(play2(pickRandomSoundFrequency())); 
} 
play2(int soundFrequency) async { 
    final result = audioPlayer.play("urltosound.wav"); 
} 

基本上,只要第一个未来了吧,我叫下一个用。那么()方法。

我从中得到的是这样的错误:

type '_Future' is not a subtype of type '(dynamic) => dynamic' of 'f' where _Future is from dart:async 

我该如何解决这个问题?

感谢

回答

5

你打错类型的.then()的说法。尝试:

.then((_) => play2(pickRandomSoundFrequency())) 

你需要传递一个函数被调用,构建参数then在不调用该函数。