网络 SDK 包含中间生成代码,更新脚本,升级版本号,隔离 pre-commit 脚本范围

This commit is contained in:
Cody
2026-03-10 19:22:58 +08:00
parent 890e102543
commit db8d269944
7 changed files with 1294 additions and 226 deletions

View File

@@ -31,3 +31,7 @@ migrate_working_dir/
.flutter-plugins-dependencies
/build/
/coverage/
# Generated files are committed so git-tag consumers can build without running build_runner
!*.g.dart
!*.freezed.dart

View File

@@ -0,0 +1,572 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'api_error.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ApiError {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ApiError);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'ApiError()';
}
}
/// @nodoc
class $ApiErrorCopyWith<$Res> {
$ApiErrorCopyWith(ApiError _, $Res Function(ApiError) __);
}
/// Adds pattern-matching-related methods to [ApiError].
extension ApiErrorPatterns on ApiError {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( _NoNetworkConnection value)? noNetworkConnection,TResult Function( _Timeout value)? timeout,TResult Function( _NetworkError value)? networkError,TResult Function( _DecodingError value)? decodingError,TResult Function( _ApiError value)? apiError,TResult Function( _Cancelled value)? cancelled,TResult Function( _Unknown value)? unknown,required TResult orElse(),}){
final _that = this;
switch (_that) {
case _NoNetworkConnection() when noNetworkConnection != null:
return noNetworkConnection(_that);case _Timeout() when timeout != null:
return timeout(_that);case _NetworkError() when networkError != null:
return networkError(_that);case _DecodingError() when decodingError != null:
return decodingError(_that);case _ApiError() when apiError != null:
return apiError(_that);case _Cancelled() when cancelled != null:
return cancelled(_that);case _Unknown() when unknown != null:
return unknown(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( _NoNetworkConnection value) noNetworkConnection,required TResult Function( _Timeout value) timeout,required TResult Function( _NetworkError value) networkError,required TResult Function( _DecodingError value) decodingError,required TResult Function( _ApiError value) apiError,required TResult Function( _Cancelled value) cancelled,required TResult Function( _Unknown value) unknown,}){
final _that = this;
switch (_that) {
case _NoNetworkConnection():
return noNetworkConnection(_that);case _Timeout():
return timeout(_that);case _NetworkError():
return networkError(_that);case _DecodingError():
return decodingError(_that);case _ApiError():
return apiError(_that);case _Cancelled():
return cancelled(_that);case _Unknown():
return unknown(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _NoNetworkConnection value)? noNetworkConnection,TResult? Function( _Timeout value)? timeout,TResult? Function( _NetworkError value)? networkError,TResult? Function( _DecodingError value)? decodingError,TResult? Function( _ApiError value)? apiError,TResult? Function( _Cancelled value)? cancelled,TResult? Function( _Unknown value)? unknown,}){
final _that = this;
switch (_that) {
case _NoNetworkConnection() when noNetworkConnection != null:
return noNetworkConnection(_that);case _Timeout() when timeout != null:
return timeout(_that);case _NetworkError() when networkError != null:
return networkError(_that);case _DecodingError() when decodingError != null:
return decodingError(_that);case _ApiError() when apiError != null:
return apiError(_that);case _Cancelled() when cancelled != null:
return cancelled(_that);case _Unknown() when unknown != null:
return unknown(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? noNetworkConnection,TResult Function()? timeout,TResult Function( String message)? networkError,TResult Function( String message)? decodingError,TResult Function( int code, String message)? apiError,TResult Function()? cancelled,TResult Function( String? message)? unknown,required TResult orElse(),}) {final _that = this;
switch (_that) {
case _NoNetworkConnection() when noNetworkConnection != null:
return noNetworkConnection();case _Timeout() when timeout != null:
return timeout();case _NetworkError() when networkError != null:
return networkError(_that.message);case _DecodingError() when decodingError != null:
return decodingError(_that.message);case _ApiError() when apiError != null:
return apiError(_that.code,_that.message);case _Cancelled() when cancelled != null:
return cancelled();case _Unknown() when unknown != null:
return unknown(_that.message);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() noNetworkConnection,required TResult Function() timeout,required TResult Function( String message) networkError,required TResult Function( String message) decodingError,required TResult Function( int code, String message) apiError,required TResult Function() cancelled,required TResult Function( String? message) unknown,}) {final _that = this;
switch (_that) {
case _NoNetworkConnection():
return noNetworkConnection();case _Timeout():
return timeout();case _NetworkError():
return networkError(_that.message);case _DecodingError():
return decodingError(_that.message);case _ApiError():
return apiError(_that.code,_that.message);case _Cancelled():
return cancelled();case _Unknown():
return unknown(_that.message);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function()? noNetworkConnection,TResult? Function()? timeout,TResult? Function( String message)? networkError,TResult? Function( String message)? decodingError,TResult? Function( int code, String message)? apiError,TResult? Function()? cancelled,TResult? Function( String? message)? unknown,}) {final _that = this;
switch (_that) {
case _NoNetworkConnection() when noNetworkConnection != null:
return noNetworkConnection();case _Timeout() when timeout != null:
return timeout();case _NetworkError() when networkError != null:
return networkError(_that.message);case _DecodingError() when decodingError != null:
return decodingError(_that.message);case _ApiError() when apiError != null:
return apiError(_that.code,_that.message);case _Cancelled() when cancelled != null:
return cancelled();case _Unknown() when unknown != null:
return unknown(_that.message);case _:
return null;
}
}
}
/// @nodoc
class _NoNetworkConnection implements ApiError {
const _NoNetworkConnection();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NoNetworkConnection);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'ApiError.noNetworkConnection()';
}
}
/// @nodoc
class _Timeout implements ApiError {
const _Timeout();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Timeout);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'ApiError.timeout()';
}
}
/// @nodoc
class _NetworkError implements ApiError {
const _NetworkError(this.message);
final String message;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$NetworkErrorCopyWith<_NetworkError> get copyWith => __$NetworkErrorCopyWithImpl<_NetworkError>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NetworkError&&(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType,message);
@override
String toString() {
return 'ApiError.networkError(message: $message)';
}
}
/// @nodoc
abstract mixin class _$NetworkErrorCopyWith<$Res> implements $ApiErrorCopyWith<$Res> {
factory _$NetworkErrorCopyWith(_NetworkError value, $Res Function(_NetworkError) _then) = __$NetworkErrorCopyWithImpl;
@useResult
$Res call({
String message
});
}
/// @nodoc
class __$NetworkErrorCopyWithImpl<$Res>
implements _$NetworkErrorCopyWith<$Res> {
__$NetworkErrorCopyWithImpl(this._self, this._then);
final _NetworkError _self;
final $Res Function(_NetworkError) _then;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? message = null,}) {
return _then(_NetworkError(
null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _DecodingError implements ApiError {
const _DecodingError(this.message);
final String message;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$DecodingErrorCopyWith<_DecodingError> get copyWith => __$DecodingErrorCopyWithImpl<_DecodingError>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _DecodingError&&(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType,message);
@override
String toString() {
return 'ApiError.decodingError(message: $message)';
}
}
/// @nodoc
abstract mixin class _$DecodingErrorCopyWith<$Res> implements $ApiErrorCopyWith<$Res> {
factory _$DecodingErrorCopyWith(_DecodingError value, $Res Function(_DecodingError) _then) = __$DecodingErrorCopyWithImpl;
@useResult
$Res call({
String message
});
}
/// @nodoc
class __$DecodingErrorCopyWithImpl<$Res>
implements _$DecodingErrorCopyWith<$Res> {
__$DecodingErrorCopyWithImpl(this._self, this._then);
final _DecodingError _self;
final $Res Function(_DecodingError) _then;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? message = null,}) {
return _then(_DecodingError(
null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _ApiError implements ApiError {
const _ApiError({required this.code, required this.message});
final int code;
final String message;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ApiErrorCopyWith<_ApiError> get copyWith => __$ApiErrorCopyWithImpl<_ApiError>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ApiError&&(identical(other.code, code) || other.code == code)&&(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType,code,message);
@override
String toString() {
return 'ApiError.apiError(code: $code, message: $message)';
}
}
/// @nodoc
abstract mixin class _$ApiErrorCopyWith<$Res> implements $ApiErrorCopyWith<$Res> {
factory _$ApiErrorCopyWith(_ApiError value, $Res Function(_ApiError) _then) = __$ApiErrorCopyWithImpl;
@useResult
$Res call({
int code, String message
});
}
/// @nodoc
class __$ApiErrorCopyWithImpl<$Res>
implements _$ApiErrorCopyWith<$Res> {
__$ApiErrorCopyWithImpl(this._self, this._then);
final _ApiError _self;
final $Res Function(_ApiError) _then;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? code = null,Object? message = null,}) {
return _then(_ApiError(
code: null == code ? _self.code : code // ignore: cast_nullable_to_non_nullable
as int,message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _Cancelled implements ApiError {
const _Cancelled();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Cancelled);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'ApiError.cancelled()';
}
}
/// @nodoc
class _Unknown implements ApiError {
const _Unknown(this.message);
final String? message;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$UnknownCopyWith<_Unknown> get copyWith => __$UnknownCopyWithImpl<_Unknown>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Unknown&&(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType,message);
@override
String toString() {
return 'ApiError.unknown(message: $message)';
}
}
/// @nodoc
abstract mixin class _$UnknownCopyWith<$Res> implements $ApiErrorCopyWith<$Res> {
factory _$UnknownCopyWith(_Unknown value, $Res Function(_Unknown) _then) = __$UnknownCopyWithImpl;
@useResult
$Res call({
String? message
});
}
/// @nodoc
class __$UnknownCopyWithImpl<$Res>
implements _$UnknownCopyWith<$Res> {
__$UnknownCopyWithImpl(this._self, this._then);
final _Unknown _self;
final $Res Function(_Unknown) _then;
/// Create a copy of ApiError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? message = freezed,}) {
return _then(_Unknown(
freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
// dart format on

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
name: networks_sdk
description: HTTP and WebSocket communication SDK.
resolution: workspace
version: 0.0.1
version: 0.0.2
homepage:
environment:

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Code generation for networks_sdk — clean lock/cache, resolve deps, run build_runner
#
# Usage:
# bash scripts/gen.sh
#
# Generated files (*.freezed.dart, *.g.dart) are committed to git so that
# git-tag consumers can build without running build_runner themselves.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDK_DIR="$(dirname "$SCRIPT_DIR")"
cd "$SDK_DIR"
# ── Clean stale lock and tool cache ────────────────────────────────────────
echo "==> Removing pubspec.lock and .dart_tool..."
rm -rf pubspec.lock .dart_tool
# ── Resolve dependencies ────────────────────────────────────────────────────
echo "==> Running flutter pub get..."
flutter pub get
# ── Run build_runner ────────────────────────────────────────────────────────
echo "==> Running build_runner build..."
dart run build_runner build --delete-conflicting-outputs
echo ""
echo "networks_sdk code generation complete."