当前位置:网站首页>Flutter network and data storage framework construction-b1
Flutter network and data storage framework construction-b1
2022-07-03 18:57:00 【weixin_ thirty-eight million one hundred and seven thousand fou】

HitNet framework
Configuration based request encapsulation and hi_net Architecture building

enum HttpMethod{GET, POST, DELETE}
/// Basic request
abstract class BaseRequest{
var pathParams;
var useHttps = true;
String authority(){
return "api.devio.org";
}
HttpMethod httpMethod();
String path();
String url(){
Uri uri;
var pathStr = path();
// Splicing path Parameters
if(pathParams != null){
if(path().endsWith("/")){
pathStr = "${path()}$pathParams";
}else{
pathStr = "${path()}/$pathParams";
}
}
// htttp and https Switch
if(useHttps){
uri = Uri.https(authority(), pathStr,params);
}else{
uri = Uri.http(authority(), pathStr,params);
}
print("url:${uri.toString()}");
return uri.toString();
}
// Log in
bool needLogin();
Map<String,String>params = Map();
// Add parameter
BaseRequest add(String k,Object v){
params[k] = v.toString();
return this;
}
Map<String,dynamic> header = Map();
// add to header
BaseRequest addHeader(String k,Object v){
params[k] = v.toString();
return this;
}
}import 'package:flutter_bilibli_app/http/request/base_request.dart';
class TestRequest extends BaseRequest{
@override
HttpMethod httpMethod() {
return HttpMethod.GET;
}
@override
bool needLogin() {
return false;
}
@override
String path() {
return 'uapi/test/test';
}
}import 'package:flutter_bilibli_app/http/request/base_request.dart';
class HiNet{
HiNet._();
static HiNet? _instance;
static HiNet? getInstance(){
if(_instance == null){
_instance = HiNet._();
}
return _instance;
}
Future fire(BaseRequest request) async{
var response = await send(request);
var result = response['data'];
print(result);
return result;
}
Future<dynamic>send<T>(BaseRequest request) async{
print('url:${request.url()}');
print('method:${request.httpMethod()}');
request.addHeader("token", "123");
print('header:${request.header}');
return Future.value({
"statusCode":200,
"data":{"code":0,"message":'success'}
});
}
void printLog(log){
print('hi_net:${log.toString()}');
}
}hi_net Unified exception and return handling and Adapter Pattern design
边栏推荐
- Briefly describe the quantitative analysis system of services
- In addition to the prickles that pierce your skin, there are poems and distant places that originally haunt you in plain life
- Opencv learning notes (continuously updated)
- Reappearance of ASPP (atlas spatial pyramid pooling) code
- Simple solution of physical backup and restore of Damon database
- CTO and programmer were both sentenced for losing control of the crawler
- 知其然,而知其所以然,JS 对象创建与继承【汇总梳理】
- Scrapy爬虫框架
- Compose LazyColumn 顶部添加控件
- Raft log replication
猜你喜欢

Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing

Implementation of cqrs architecture mode under Kratos microservice framework

Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification

Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement

我眼中真正优秀的CTO长啥样

Transformer T5 model read slowly

Web3 credential network project galaxy is better than nym?

Ping problem between virtual machine and development board
![Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]](/img/d4/cbbaec40119be6cb5594899e348261.png)
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]

SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
随机推荐
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
【光学】基于matlab介电常数计算【含Matlab源码 1926期】
[Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
Briefly describe the quantitative analysis system of services
Flutter网络和数据存储框架搭建 -b1
C enum contains value - C enum contains value
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
DriveSeg:动态驾驶场景分割数据集
SSH 远程执行命令简介
Know what it is, and know why, JS object creation and inheritance [summary and sorting]
leetcode:556. 下一个更大元素 III【模拟 + 尽可能少变更】
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
Usage of laravel conditional array in
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
为什么要做特征的归一化/标准化?
Torch learning notes (4) -- torch's dynamic calculation diagram
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Su embedded training - Day10
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon