实用模板

一个用于常见小部件和有用脚本的模板文件夹

合作作者: PratikJH153

  1. REST API Dart 代码
    一个可直接使用的仓库,包含使用 Dio 包调用 GET、POST、DELETE 和 PATCH 方法的代码。

工作
a. database.dart:在此文件中指定应用程序的端点。它包含用于切换变量
在调试模式和生产模式之间,以及为各种错误创建的自定义消息。

unpackLocally: A function that takes in response body of a REST API call and returns a map containing two parameters: 
"success": 0/1 (0 for failure 1 for successful result) and 
"unpacked": <response data>. 

In case of call failure "unpacked" will return a message corresponding to the type of error 
and the response data otherwise ie. in case of a successful request.

b. rest_apis.dart:包含负责处理异步 API 调用的 REQUEST 函数的文件。

 Returns a Map containing local_result and local_status parameters.
 local_status: 200 If the server responds 500 in case of a Timeout

c. apis.dart:一个包含您将在整个项目中使用的所有 API 的文件。这些函数需要
根据项目定制,但遵循简单的模式。

 Parameters: In case a request url consists of a parameter 
 eg: endpoint/folder/innerfolder/$unique_variable, 
 
 A single parameter can be used and passed along the request.
 
 Eg: 
 static Future<Map> getProductData(String id) async {
    if (kDebugMode) {
      print("CALLING getProductData(String id)");
    }
    String endpoint = "users/products/getProductData/$id";
    return GET(endpoint);
  }

  Similarly, String id can be replaced by Map? body for requests requiring a Request Body

GitHub

查看 Github