Future<List<Books>> vs Future<List<Future<Books>>>

47 views Asked by At

How do we change the function below, so it returns Future<List> instead of Future<List<Future>>

Future<List<Future<Books>>> searchBook(String searchString) async {

    return await  appDb.customSelect(
      'SELECT * FROM books',
      readsFrom: {appDb.books},
    ).map(appDb.books.mapFromRow).get();
  }

I'm using drift_sqflite: ^2.0.1 drift: ^2.13.0

1

There are 1 answers

0
Md. Yeasin Sheikh On

You can use Future.wait

Future<List<Books>> getBooks() async {
  final items = await searchBook();
  final result = Future.wait(items);
  return result;
}

Or just `

Future<List<Books>> getBooks() async => await Future.wait(await searchBook());