Commit 198b54b6 authored by 汪林玲's avatar 汪林玲

支持空安全

parents
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: 1aafb3a8b9b0c36241c5f5b34ee914770f015818
channel: stable
project_type: package
## [0.0.1] - TODO: Add release date.
* TODO: Describe initial release.
TODO: Add your license here.
# app_base_repository
A new Flutter package project.
## Getting Started
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
library base_repository;
export 'package:dio/dio.dart';
export 'src/http/ds_dio_util.dart';
export 'src/entity/ds_response_object.dart';
export 'src/entity/ds_response_bool.dart';
export 'src/entity/ds_response_dynamic.dart';
export 'src/entity/sysnet_error.dart';
export 'src/entity/ds_response_string.dart';
export 'src/entity/ds_response_list.dart';
import 'ds_response_object.dart';
class DSResponseBool extends BaseResponse<String?> {
DSResponseBool(code, msg, data) : super(code, msg, data);
factory DSResponseBool.fromJson(jsonMap) => $DSResponseBoolFromJson(jsonMap);
Map<String, dynamic> toJson() => $DSResponseBoolToJson(this);
}
DSResponseBool $DSResponseBoolFromJson(Map<String, dynamic> jsonMap) {
int? code = jsonMap['code'] as int?;
String? msg = jsonMap['msg'] as String?;
String? data = '';
try {
if(jsonMap['data'] is List && List<dynamic>.from(jsonMap['data']).length<=0){
data = msg;
}
} catch (e) {
}
return DSResponseBool(code,msg,data);
}
Map<String, dynamic> $DSResponseBoolToJson(DSResponseBool instance) =>
<String, dynamic>{
'code': instance.code,
'msg': instance.msg,
'data': instance.data,
};
import 'ds_response_object.dart';
class DSResponseDynamic extends BaseResponse<dynamic> {
DSResponseDynamic(code, msg, data) : super(code, msg, data);
factory DSResponseDynamic.fromJson(jsonMap) =>
$DSResponseDynamicFromJson(jsonMap);
Map<String, dynamic> toJson() => $DSResponseDynamicToJson(this);
}
DSResponseDynamic $DSResponseDynamicFromJson(Map<String, dynamic> jsonMap) {
int? code = jsonMap['code'] as int?;
String? msg = jsonMap['msg'] as String?;
dynamic data = jsonMap['data'];
return DSResponseDynamic(code, msg, data);
}
Map<String, dynamic> $DSResponseDynamicToJson(DSResponseDynamic instance) =>
<String, dynamic>{
'code': instance.code,
'msg': instance.msg,
'data': instance.data,
};
import 'ds_response_object.dart';
class DSResponseList<T> extends BaseResponse<List<T>> {
DSResponseList(code, msg, data) : super(code, msg, data);
factory DSResponseList.fromJson(jsonMap, DecodeFunction decodeFunction) =>
$DSResponseListFromJson<T>(jsonMap, decodeFunction);
Map<String, dynamic> toJson(EncodeFunction encodeFunction) =>
$DSResponseListToJson<T>(this, encodeFunction);
}
DSResponseList<T> $DSResponseListFromJson<T>(
Map<String, dynamic> jsonMap, DecodeFunction decodeFunction) {
List<T> data = [];
if (jsonMap['data'] != null) {
if(jsonMap['data'] is List){
data = List<T>.from((jsonMap['data'] as List).map((item) => decodeFunction(item)));
}else if(jsonMap['data'] is Map){
Map<String,dynamic> map = jsonMap['data'];
if(map['list'] != null && map['list'] is List){
data = List<T>.from((map['list'] as List).map((item) => decodeFunction(item)));
}
}
}
return DSResponseList<T>(
jsonMap['code'] as int?,
jsonMap['msg'] as String?, data);
}
Map<String, dynamic> $DSResponseListToJson<T>(
DSResponseList<T> instance, EncodeFunction encodeFunction) =>
<String, dynamic>{
'code': instance.code,
'msg': instance.msg,
'data': instance.data.map((item) => encodeFunction(item)).toList()
};
\ No newline at end of file
typedef DecodeFunction<T> = T Function(Map<String, dynamic>?);
typedef EncodeFunction<T> = Map<String, dynamic> Function(T?);
class DSResponseObject<T> extends BaseResponse<T?> {
DSResponseObject(code, msg, data) : super(code, msg, data);
factory DSResponseObject.fromJson(Map<String, dynamic> jsonMap, DecodeFunction<T> decodeFunction) => $DSResponseObjectFromJson<T>(jsonMap, decodeFunction);
Map<String, dynamic> toJson(EncodeFunction<T> encodeFun) =>
$DSResponseObjectToJson<T>(this, encodeFun);
}
DSResponseObject<T> $DSResponseObjectFromJson<T>(Map<String, dynamic> jsonMap, DecodeFunction<T> decodeFunction){
int? code = jsonMap['code'] as int?;
String? msg = jsonMap['msg'] as String?;
dynamic data;
if(jsonMap['data'] != null && jsonMap['data'] is Map){
data = decodeFunction(jsonMap['data']);
}
return DSResponseObject<T>(code,msg,data);
}
Map<String, dynamic> $DSResponseObjectToJson<T>(
DSResponseObject<T> instance, EncodeFunction<T> encodeFunction) =>
<String, dynamic>{
'code': instance.code,
'msg': instance.msg,
'data': encodeFunction(instance.data)
};
class BaseResponse<T> {
final int? code;
final String? msg;
final T data;
BaseResponse(this.code, this.msg, this.data);
bool get isSuccess => code == 2000;
}
\ No newline at end of file
import 'ds_response_object.dart';
class DSResponseString extends BaseResponse<String?> {
DSResponseString(code, msg, data) : super(code, msg, data);
factory DSResponseString.fromJson(jsonMap) => $DSResponseStringFromJson(jsonMap);
Map<String, dynamic> toJson() => $DSResponseStringToJson(this);
}
DSResponseString $DSResponseStringFromJson(Map<String, dynamic> jsonMap) {
int? code = jsonMap['code'] as int?;
String? msg = jsonMap['msg'] as String?;
String? data = '';
try {
if(jsonMap['data'] is List && List<dynamic>.from(jsonMap['data']).length<=0){
data = msg;
}
} catch (e) {
}
return DSResponseString(code,msg,data);
}
Map<String, dynamic> $DSResponseStringToJson(DSResponseString instance) =>
<String, dynamic>{
'code': instance.code,
'msg': instance.msg,
'data': instance.data,
};
class SysnetError implements Exception {
final Exception exception;
final String message;
final SysnetErrorType type;
final int code;
SysnetError({
required this.exception,
required this.message,
required this.type,
required this.code,
});
}
enum SysnetErrorType {
/// It occurs when url is opened timeout.
connectTimeout,
/// It occurs when url is sent timeout.
sendTimeout,
///It occurs when receiving timeout.
receiveTimeout,
/// When the server response, but with a incorrect status, such as 404, 503...
response,
/// When the request is cancelled, dio will throw a error with this type.
cancel,
/// Default error type, Some other Error. In this case, you can
/// use the DioError.error if it is not null.
other,
}
\ No newline at end of file
import 'dart:io';
import 'package:dio/adapter.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
class DSDioUtil {
static final DSDioUtil _singleton = DSDioUtil._init();
static Dio? _dio;
static DSDioUtil getInstance() {
return _singleton;
}
factory DSDioUtil() {
return _singleton;
}
///
/// Dio 初始化
/// baseUrl BASEURL,请求的基础url
/// connectTimeout 连接超时时间(默认10s)
/// receiveTimeout 接收超时时间(默认10s)
/// inject 拦截处理
/// proxyAddress 代理处理
///
void init({
required String baseUrl,
int connectTimeout = 1000 * 10,
int receiveTimeout = 1000 * 10,
InterceptorsWrapper? inject,
String? proxyAddress,
}) {
_dio = Dio(BaseOptions(
baseUrl: baseUrl,
connectTimeout: connectTimeout,
receiveTimeout: receiveTimeout,
));
if (inject != null) {
_dio!.interceptors.add(InterceptorsWrapper(
onRequest: inject.onRequest,
onResponse: inject.onResponse,
onError: inject.onError,
));
}
if (proxyAddress != null && proxyAddress.isNotEmpty) {
(_dio!.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
client.findProxy = (uri) {
return '$proxyAddress';
};
};
}
}
DSDioUtil._init();
///
/// GET 方法请求
/// url 请求的地址
/// queryParameters 请求的参数信息
/// options 每个请求独立的options
/// cancelToken 取消请求的Token
///
Future<dynamic> get(
String url, {
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
}) async {
if (_dio == null) {
throw ErrorHint('Dio 未初始化,请先进行初始化');
}
Response response = await _dio!.get(
url,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
);
return response.data;
}
///
/// POST 方法请求
/// url 请求的地址
/// data 请求Body中的数据
/// queryParameters 请求From表单中的数据
/// options 每个请求独立的options
/// cancelToken 取消请求的Token
///
Future<dynamic> post(
String url, {
dynamic data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
}) async {
if (_dio == null) {
throw ErrorHint('Dio 未初始化,请先进行初始化');
}
Response<dynamic> response = await _dio!.post(
url,
data: data,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
);
if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) {
return response.data;
}
//可以抛出一个特定的异常信息
return response.data;
}
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.15.0"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
name: base_repository
description: 基础网络库.
version: 0.0.1
homepage:
environment:
sdk: '>=2.12.0 <3.0.0'
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
dio: ^4.0.0
dev_dependencies:
flutter_test:
sdk: flutter
\ No newline at end of file
import 'package:flutter_test/flutter_test.dart';
void main() {
test('测试', () {});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment