0

So I wanted to use audio query to list out the songs in flutter, According to their documentation

List<SongInfo> songs = await audioQuery.getSongs();

is the way to do the job,

But await can't work without async being defined. Can any solve this?

Marcos Boaventura
  • 4,641
  • 1
  • 20
  • 27
Tushar
  • 33
  • 9
  • `await` can be called only in `async` method, more: https://dart.dev/codelabs/async-await#why-asynchronous-code-matters – pskink Mar 15 '20 at 04:54
  • You could use `Future`'s `then` syntax. `audioQuery.getSongs().then(...)` However, I suspect that the reason you don't want to use await indicates that you are trying to use this API in the wrong place. – Richard Heap Mar 15 '20 at 10:11
  • @RichardHeap Actually the above syntax is given in the documentation of the audioquery package. Actually asynchronous programming is necessary for it search the songs from my device. So how can I put async keyword when List songs = await audioQuery.getSongs(); is the only statement required to list the songs. I hope you are getting my point – Tushar Mar 16 '20 at 03:56
  • *"So how can I put async keyword when ..."* see https://dart.dev/codelabs/async-await – pskink Mar 16 '20 at 04:41
  • @Tushar I think you question by explaining why you can't use the statement as it is – Alex.F Oct 15 '20 at 21:46

0 Answers0