当前位置:网站首页>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
边栏推荐
- Raft log replication
- Help change the socket position of PCB part
- How to quickly view the inheritance methods of existing models in torchvision?
- Dynamic planning -- expansion topics
- Sepconv (separable revolution) code recurrence
- Software development freelancer's Road
- What does foo mean in programming?
- Usage of laravel conditional array in
- DriveSeg:动态驾驶场景分割数据集
- Su embedded training - Day10
猜你喜欢
Record: solve the problem that MySQL is not an internal or external command environment variable
为什么要做特征的归一化/标准化?
leetcode:556. Next larger element III [simulation + change as little as possible]
我们做了一个智能零售结算平台
CV in transformer learning notes (continuously updated)
The installation path cannot be selected when installing MySQL 8.0.23
A green plug-in that allows you to stay focused, live and work hard
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
DriveSeg:动态驾驶场景分割数据集
随机推荐
简述服务量化分析体系
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
[leetcode weekly race] game 300 - 6110 Number of incremental paths in the grid graph - difficult
Torch learning notes (5) -- autograd
Caddy server agent
High concurrency Architecture - distributed search engine (ES)
Scrape crawler framework
虚拟机和开发板互Ping问题
Zhengda futures news: soaring oil prices may continue to push up global inflation
Record: pymysql is used in pycharm to connect to the database
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
Torch learning notes (2) -- 11 common operation modes of tensor
leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
my. INI file not found
Day-27 database
[combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
How to read the source code [debug and observe the source code]
Smart wax therapy machine based on STM32 and smart cloud
Dart JSON编码器和解码器剖析