当前位置:网站首页>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模式设计
边栏推荐
- Sustainable service business models
- 235. 二叉搜索樹的最近公共祖先【lca模板 + 找路徑相同】
- 知其然,而知其所以然,JS 对象创建与继承【汇总梳理】
- Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
- 2022-2028 global physiotherapy clinic industry research and trend analysis report
- 235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】
- [combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
- In addition to the prickles that pierce your skin, there are poems and distant places that originally haunt you in plain life
- webcodecs
- 199. Right view of binary tree - breadth search
猜你喜欢

Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)

Recommend a simple browser tab

User identity used by startup script and login script in group policy

KINGS

The installation path cannot be selected when installing MySQL 8.0.23

Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download

Install apache+php+mysql+phpmyadmin xampp and its error resolution

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

2022-2028 global solid phase extraction column industry research and trend analysis report

Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
随机推荐
Help change the socket position of PCB part
Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?
Know what it is, and know why, JS object creation and inheritance [summary and sorting]
Coordinate layer conversion tool (video)
Shell script return value with which output
application
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
[leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难
How many convolution methods does deep learning have? (including drawings)
Which do MySQL and Oracle learn?
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
flask 生成swagger文档
Hard disk monitoring and analysis tool: smartctl
How to read the source code [debug and observe the source code]
Torch learning notes (1) -- 19 common ways to create tensor
What London Silver Trading software supports multiple languages
High concurrency architecture cache
Usage of laravel conditional array in
shell 脚本中关于用户输入参数的处理