Home > Net >  Flutter merge search queries?
Flutter merge search queries?

Time:02-19

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, Address address) async {
  Uri uri = Helper.getUri('api/foods');
  Map<String, dynamic> _queryParams = {};
  _queryParams['search'] = '$search';
  _queryParams['searchFields'] = 'name:like;';
  _queryParams['limit'] = '70';
  if (!address.isUnknown()) {
    _queryParams['myLon'] = address.longitude.toString();
    _queryParams['myLat'] = address.latitude.toString();
    _queryParams['areaLon'] = address.longitude.toString();
    _queryParams['areaLat'] = address.latitude.toString();
  }
  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({}));
  }
}

CodePudding user response:

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.

CodePudding user response:

yeah, actually like I can get out of here.

What do I need to do in order for the results of streamedRest and streamedRest2 to appear sequentially in the area I marked?

Future<Stream<Food>> searchFoods(String search, Address address) async {
  Uri uri = Helper.getUri('api/foods');
  Uri uri2 = Helper.getUri('api/foods');
  Map<String, dynamic> _queryParams = {};
  _queryParams['search'] = '$search';
  _queryParams['searchFields'] = 'name:like;';
  _queryParams['limit'] = '70';
  Map<String, dynamic> _queryParams2 = {};
  _queryParams2['search'] = '$search';
  _queryParams2['searchFields'] = 'description:like';
  _queryParams2['limit'] = '70';
  uri = uri.replace(queryParameters: _queryParams);
  uri2 = uri.replace(queryParameters: _queryParams2);
  try {
    final client = new http.Client();
    final streamedRest = await client.send(http.Request('get', uri));
    final streamedRest2 = await client.send(http.Request('get', uri2));
############################TOP    
    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);
    });
  }
############################END
catch (e) {
    print(CustomTrace(StackTrace.current, message: uri.toString()).toString());
    return new Stream.value(new Food.fromJSON({}));
  }
}
  • Related