简体   繁体   English

如何将此数据应用到 flutter API 中?

[英]How to apply this data into flutter API?

  • Api Paramter: Api 参数:

Send below values in request in "getProducts" whats new:- sort_by: product_id, sort_order: desc Price- High to Low:- sort_by: price, sort_order: desc Price- Low to high:- sort_by: price, sort_order: asc New to Old:- sort_by: product_id, sort_order: desc Old to new:- sort_by: product_id, sort_order: asc Discount:- sort_by: discount, sort_order: desc在“getProducts”的请求中发送以下值 最新消息:- sort_by: product_id, sort_order: desc Price- 从高到低:- sort_by: price, sort_order: desc Price- 从低到高:- sort_by: price, sort_order: asc 新到旧:- sort_by:product_id,sort_order:desc 从旧到新:- sort_by:product_id,sort_order:asc 折扣:- sort_by:折扣,sort_order:desc

Here's a sample code try that:-这是一个示例代码尝试: -

import 'package:http/http.dart' as HTTP;
import 'dart:convert';
class API {
//replace with your endpoint
 static String BASE_URL = 'https://some-url/api/';

static Future<List<ExampleData>> getRequest() async {

Response res = await http.get(BASE_URL+'example');

  if (res.statusCode == 200) {
  List<dynamic> body = jsonDecode(res.body);
  //sort it here if you want
    
 // complete by parsing the json body return into ExampleData object and 
  return 'Your data';

  }
} 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM