当前位置:网站首页>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 (6) -- logistic regression model (self training)
- [Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
- Web3 credential network project galaxy is better than nym?
- Su embedded training - Day10
- 变化是永恒的主题
- Know what it is, and know why, JS object creation and inheritance [summary and sorting]
- High concurrency Architecture - distributed search engine (ES)
- Raft log replication
- 235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
- Shell script return value with which output
猜你喜欢
虚拟机和开发板互Ping问题
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
[leetcode weekly race] game 300 - 6110 Number of incremental paths in the grid graph - difficult
Know what it is, and know why, JS object creation and inheritance [summary and sorting]
leetcode:556. 下一个更大元素 III【模拟 + 尽可能少变更】
Help change the socket position of PCB part
G1 garbage collector of garbage collector
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
A green plug-in that allows you to stay focused, live and work hard
4. Load balancing and dynamic static separation
随机推荐
Change is the eternal theme
How many convolution methods does deep learning have? (including drawings)
High concurrency architecture cache
Getting started with JDBC
Torch learning notes (1) -- 19 common ways to create tensor
Typescript configuration
204. Count prime
Help change the socket position of PCB part
199. Right view of binary tree - breadth search
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
How about the Moco model?
Day-27 database
Work Measurement - 1
达梦数据库的物理备份和还原简解
leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
How to analyze the rising and falling rules of London gold trend chart
2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
High concurrency Architecture - read write separation
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
Add control at the top of compose lazycolumn