当前位置:网站首页>Flutter网络和数据存储框架搭建 -b1
Flutter网络和数据存储框架搭建 -b1
2022-07-03 18:46:00 【weixin_38107457】

HitNet架构
基于配置的请求封装与hi_net架构搭建

enum HttpMethod{GET, POST, DELETE}
/// 基础请求
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();
// 拼接path参数
if(pathParams != null){
if(path().endsWith("/")){
pathStr = "${path()}$pathParams";
}else{
pathStr = "${path()}/$pathParams";
}
}
// htttp 和https切换
if(useHttps){
uri = Uri.https(authority(), pathStr,params);
}else{
uri = Uri.http(authority(), pathStr,params);
}
print("url:${uri.toString()}");
return uri.toString();
}
// 是否登录
bool needLogin();
Map<String,String>params = Map();
// 添加参数
BaseRequest add(String k,Object v){
params[k] = v.toString();
return this;
}
Map<String,dynamic> header = Map();
// 添加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统一异常和返回处理与Adapter模式设计
边栏推荐
- Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
- cipher
- Dynamic planning -- expansion topics
- Torch learning notes (6) -- logistic regression model (self training)
- Work Measurement - 1
- Le changement est un thème éternel
- 4. Load balancing and dynamic static separation
- Niuke monthly race 31 minus integer
- [leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难
- Sustainable service business models
猜你喜欢

Add control at the top of compose lazycolumn

2022-2028 global aircraft head up display (HUD) industry research and trend analysis report

论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding

4. Load balancing and dynamic static separation

Pan for in-depth understanding of the attention mechanism in CV

Torch learning notes (3) -- univariate linear regression model (self training)
![leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]](/img/d4/cbbaec40119be6cb5594899e348261.png)
leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]

235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】

What problems can cross-border e-commerce sellers solve with multi platform ERP management system

2022-2028 global petroleum pipe joint industry research and trend analysis report
随机推荐
Pan for in-depth understanding of the attention mechanism in CV
Administrative division code acquisition
Usage of laravel conditional array in
How to analyze the rising and falling rules of London gold trend chart
Nodejs (01) - introductory tutorial
What is SQL get connection
Dynamic planning -- expansion topics
Web3 credential network project galaxy is better than nym?
Common PostgreSQL commands
平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
Database creation, addition, deletion, modification and query
“google is not defined” when using Google Maps V3 in Firefox remotely
What is the function of registering DLLs- What does registering a DLL do?
Su embedded training - Day10
[combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
變化是永恒的主題
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Typescript official website tutorial
Torch learning notes (2) -- 11 common operation modes of tensor