当前位置:网站首页>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
边栏推荐
- MySQL duplicate check
- How to quickly view the inheritance methods of existing models in torchvision?
- [leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难
- [Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
- CV in transformer learning notes (continuously updated)
- Read the paper glodyne global topology preserving dynamic network embedding
- Recommend a simple browser tab
- Change is the eternal theme
- [combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
- leetcode:556. Next larger element III [simulation + change as little as possible]
猜你喜欢
Record: MySQL changes the time zone
Add control at the top of compose lazycolumn
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]
Smart wax therapy machine based on STM32 and smart cloud
12、 Service management
Unity webgl optimization
leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
随机推荐
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
There are several levels of personal income tax
Differential constrained SPFA
[leetcode weekly race] game 300 - 6110 Number of incremental paths in the grid graph - difficult
Raft log replication
SQL: special update operation
Getting started with JDBC
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Help change the socket position of PCB part
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
Work Measurement - 1
Transformer T5 model read slowly
Scrape crawler framework
2022.02.11
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Database creation, addition, deletion, modification and query
达梦数据库的物理备份和还原简解
Scrapy爬虫框架