'Flutter merge search queries?

We have a Laravel + Flutter based platform.

When a search query is returned in our Flutter application, it prints the products on the screen by making an API call as follows. api/foods?search=EXAMPLE;&searchFields=name:like;&limit:70; Our search is sorted by name.

When I search for "EXAMPLE", I want a listing based on the name, followed by products with "EXAMPLE" in the description. So this query; api/foods?search=EXAMPLE;&searchFields=description:like;&limit:70;

I mean, having these two queries done one after the other; How can I list it in the search results so that it lists the name first and then the description?

yani EXAMPLE aramasının sonucunda önce "api/foods?search=EXAMPLE;&searchFields=name:like;&limit:70;" sorgusu, altında da birleşik bir şekilde "api/foods?search=EXAMPLE;&searchFields=description:like;&limit:70;" sorgusunun yer almasını istiyorum.

Flutter Codes;

Future<Stream<Food>> searchFoods(String search) async {
  Uri uri = Helper.getUri('api/foods');
  Map<String, dynamic> _queryParams = {};
  _queryParams['search'] = '$search';
  _queryParams['searchFields'] = 'name:like;';
  _queryParams['limit'] = '70';
  uri = uri.replace(queryParameters: _queryParams);
  try {
    final client = new http.Client();
    final streamedRest = await client.send(http.Request('get', uri));

    return streamedRest.stream.transform(utf8.decoder).transform(json.decoder).map((data) => Helper.getData(data)).expand((data) => (data as List)).map((data) {
      return Food.fromJSON(data);
    });
  } catch (e) {
    print(CustomTrace(StackTrace.current, message: uri.toString()).toString());
    return new Stream.value(new Food.fromJSON({}));
  }
}


Solution 1:[1]

One option is to have 2 ListViews in the Column so that you can display results from 2 lists. The other option is to merge the list into one and then send it to your UI to display in single ListView.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhishek Doshi