This commit is contained in:
chen08209
2026-03-11 10:24:38 +08:00
parent 3f5e7b80bc
commit 7b46347016
12 changed files with 467 additions and 329 deletions

View File

@@ -128,6 +128,17 @@ abstract class ProxyGroup with _$ProxyGroup {
_$ProxyGroupFromJson(json);
}
@freezed
abstract class Proxy with _$Proxy {
const factory Proxy({
required String name,
required String type,
String? now,
}) = _Proxy;
factory Proxy.fromJson(Map<String, Object?> json) => _$ProxyFromJson(json);
}
@freezed
abstract class RuleProvider with _$RuleProvider {
const factory RuleProvider({required String name}) = _RuleProvider;
@@ -431,12 +442,14 @@ abstract class ClashConfig with _$ClashConfig {
const factory ClashConfig({
@Default([]) @JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups,
@JsonKey(fromJson: _genRule) @Default([]) List<Rule> rules,
@Default([]) List<Proxy> proxies,
// @JsonKey(name: 'rule-providers', fromJson: _genRuleProviders)
// @Default([])
// List<RuleProvider> ruleProvider,
// @JsonKey(name: 'sub-rules', fromJson: _genSubRules)
// @Default([])
// List<SubRule> subRules,
@Default({}) Map<String, String> proxyTypeMap,
}) = _ClashConfig;
factory ClashConfig.fromJson(Map<String, Object?> json) =>

View File

@@ -6,6 +6,8 @@ import 'package:fl_clash/enum/enum.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'clash_config.dart';
part 'generated/common.freezed.dart';
part 'generated/common.g.dart';
@@ -285,17 +287,6 @@ extension TrafficShowExt on TrafficShow {
String get show => '$value$unit';
}
@freezed
abstract class Proxy with _$Proxy {
const factory Proxy({
required String name,
required String type,
String? now,
}) = _Proxy;
factory Proxy.fromJson(Map<String, Object?> json) => _$ProxyFromJson(json);
}
@freezed
abstract class Group with _$Group {
const factory Group({

View File

@@ -348,6 +348,275 @@ as String?,
}
/// @nodoc
mixin _$Proxy {
String get name; String get type; String? get now;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ProxyCopyWith<Proxy> get copyWith => _$ProxyCopyWithImpl<Proxy>(this as Proxy, _$identity);
/// Serializes this Proxy to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is Proxy&&(identical(other.name, name) || other.name == name)&&(identical(other.type, type) || other.type == type)&&(identical(other.now, now) || other.now == now));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,name,type,now);
@override
String toString() {
return 'Proxy(name: $name, type: $type, now: $now)';
}
}
/// @nodoc
abstract mixin class $ProxyCopyWith<$Res> {
factory $ProxyCopyWith(Proxy value, $Res Function(Proxy) _then) = _$ProxyCopyWithImpl;
@useResult
$Res call({
String name, String type, String? now
});
}
/// @nodoc
class _$ProxyCopyWithImpl<$Res>
implements $ProxyCopyWith<$Res> {
_$ProxyCopyWithImpl(this._self, this._then);
final Proxy _self;
final $Res Function(Proxy) _then;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? name = null,Object? type = null,Object? now = freezed,}) {
return _then(_self.copyWith(
name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,now: freezed == now ? _self.now : now // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// Adds pattern-matching-related methods to [Proxy].
extension ProxyPatterns on Proxy {
/// 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( _Proxy value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_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?>(TResult Function( _Proxy value) $default,){
final _that = this;
switch (_that) {
case _Proxy():
return $default(_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( _Proxy value)? $default,){
final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_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( String name, String type, String? now)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_that.name,_that.type,_that.now);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?>(TResult Function( String name, String type, String? now) $default,) {final _that = this;
switch (_that) {
case _Proxy():
return $default(_that.name,_that.type,_that.now);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( String name, String type, String? now)? $default,) {final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_that.name,_that.type,_that.now);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _Proxy implements Proxy {
const _Proxy({required this.name, required this.type, this.now});
factory _Proxy.fromJson(Map<String, dynamic> json) => _$ProxyFromJson(json);
@override final String name;
@override final String type;
@override final String? now;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ProxyCopyWith<_Proxy> get copyWith => __$ProxyCopyWithImpl<_Proxy>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ProxyToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Proxy&&(identical(other.name, name) || other.name == name)&&(identical(other.type, type) || other.type == type)&&(identical(other.now, now) || other.now == now));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,name,type,now);
@override
String toString() {
return 'Proxy(name: $name, type: $type, now: $now)';
}
}
/// @nodoc
abstract mixin class _$ProxyCopyWith<$Res> implements $ProxyCopyWith<$Res> {
factory _$ProxyCopyWith(_Proxy value, $Res Function(_Proxy) _then) = __$ProxyCopyWithImpl;
@override @useResult
$Res call({
String name, String type, String? now
});
}
/// @nodoc
class __$ProxyCopyWithImpl<$Res>
implements _$ProxyCopyWith<$Res> {
__$ProxyCopyWithImpl(this._self, this._then);
final _Proxy _self;
final $Res Function(_Proxy) _then;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? name = null,Object? type = null,Object? now = freezed,}) {
return _then(_Proxy(
name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,now: freezed == now ? _self.now : now // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
mixin _$RuleProvider {
@@ -3245,7 +3514,13 @@ as String,
/// @nodoc
mixin _$ClashConfig {
@JsonKey(name: 'proxy-groups') List<ProxyGroup> get proxyGroups;@JsonKey(fromJson: _genRule) List<Rule> get rules;
@JsonKey(name: 'proxy-groups') List<ProxyGroup> get proxyGroups;@JsonKey(fromJson: _genRule) List<Rule> get rules; List<Proxy> get proxies;// @JsonKey(name: 'rule-providers', fromJson: _genRuleProviders)
// @Default([])
// List<RuleProvider> ruleProvider,
// @JsonKey(name: 'sub-rules', fromJson: _genSubRules)
// @Default([])
// List<SubRule> subRules,
Map<String, String> get proxyTypeMap;
/// Create a copy of ClashConfig
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -3258,16 +3533,16 @@ $ClashConfigCopyWith<ClashConfig> get copyWith => _$ClashConfigCopyWithImpl<Clas
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ClashConfig&&const DeepCollectionEquality().equals(other.proxyGroups, proxyGroups)&&const DeepCollectionEquality().equals(other.rules, rules));
return identical(this, other) || (other.runtimeType == runtimeType&&other is ClashConfig&&const DeepCollectionEquality().equals(other.proxyGroups, proxyGroups)&&const DeepCollectionEquality().equals(other.rules, rules)&&const DeepCollectionEquality().equals(other.proxies, proxies)&&const DeepCollectionEquality().equals(other.proxyTypeMap, proxyTypeMap));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(proxyGroups),const DeepCollectionEquality().hash(rules));
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(proxyGroups),const DeepCollectionEquality().hash(rules),const DeepCollectionEquality().hash(proxies),const DeepCollectionEquality().hash(proxyTypeMap));
@override
String toString() {
return 'ClashConfig(proxyGroups: $proxyGroups, rules: $rules)';
return 'ClashConfig(proxyGroups: $proxyGroups, rules: $rules, proxies: $proxies, proxyTypeMap: $proxyTypeMap)';
}
@@ -3278,7 +3553,7 @@ abstract mixin class $ClashConfigCopyWith<$Res> {
factory $ClashConfigCopyWith(ClashConfig value, $Res Function(ClashConfig) _then) = _$ClashConfigCopyWithImpl;
@useResult
$Res call({
@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups,@JsonKey(fromJson: _genRule) List<Rule> rules
@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups,@JsonKey(fromJson: _genRule) List<Rule> rules, List<Proxy> proxies, Map<String, String> proxyTypeMap
});
@@ -3295,11 +3570,13 @@ class _$ClashConfigCopyWithImpl<$Res>
/// Create a copy of ClashConfig
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? proxyGroups = null,Object? rules = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? proxyGroups = null,Object? rules = null,Object? proxies = null,Object? proxyTypeMap = null,}) {
return _then(_self.copyWith(
proxyGroups: null == proxyGroups ? _self.proxyGroups : proxyGroups // ignore: cast_nullable_to_non_nullable
as List<ProxyGroup>,rules: null == rules ? _self.rules : rules // ignore: cast_nullable_to_non_nullable
as List<Rule>,
as List<Rule>,proxies: null == proxies ? _self.proxies : proxies // ignore: cast_nullable_to_non_nullable
as List<Proxy>,proxyTypeMap: null == proxyTypeMap ? _self.proxyTypeMap : proxyTypeMap // ignore: cast_nullable_to_non_nullable
as Map<String, String>,
));
}
@@ -3384,10 +3661,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules, List<Proxy> proxies, Map<String, String> proxyTypeMap)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ClashConfig() when $default != null:
return $default(_that.proxyGroups,_that.rules);case _:
return $default(_that.proxyGroups,_that.rules,_that.proxies,_that.proxyTypeMap);case _:
return orElse();
}
@@ -3405,10 +3682,10 @@ return $default(_that.proxyGroups,_that.rules);case _:
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules, List<Proxy> proxies, Map<String, String> proxyTypeMap) $default,) {final _that = this;
switch (_that) {
case _ClashConfig():
return $default(_that.proxyGroups,_that.rules);case _:
return $default(_that.proxyGroups,_that.rules,_that.proxies,_that.proxyTypeMap);case _:
throw StateError('Unexpected subclass');
}
@@ -3425,10 +3702,10 @@ return $default(_that.proxyGroups,_that.rules);case _:
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups, @JsonKey(fromJson: _genRule) List<Rule> rules, List<Proxy> proxies, Map<String, String> proxyTypeMap)? $default,) {final _that = this;
switch (_that) {
case _ClashConfig() when $default != null:
return $default(_that.proxyGroups,_that.rules);case _:
return $default(_that.proxyGroups,_that.rules,_that.proxies,_that.proxyTypeMap);case _:
return null;
}
@@ -3440,7 +3717,7 @@ return $default(_that.proxyGroups,_that.rules);case _:
@JsonSerializable()
class _ClashConfig implements ClashConfig {
const _ClashConfig({@JsonKey(name: 'proxy-groups') final List<ProxyGroup> proxyGroups = const [], @JsonKey(fromJson: _genRule) final List<Rule> rules = const []}): _proxyGroups = proxyGroups,_rules = rules;
const _ClashConfig({@JsonKey(name: 'proxy-groups') final List<ProxyGroup> proxyGroups = const [], @JsonKey(fromJson: _genRule) final List<Rule> rules = const [], final List<Proxy> proxies = const [], final Map<String, String> proxyTypeMap = const {}}): _proxyGroups = proxyGroups,_rules = rules,_proxies = proxies,_proxyTypeMap = proxyTypeMap;
factory _ClashConfig.fromJson(Map<String, dynamic> json) => _$ClashConfigFromJson(json);
final List<ProxyGroup> _proxyGroups;
@@ -3457,6 +3734,32 @@ class _ClashConfig implements ClashConfig {
return EqualUnmodifiableListView(_rules);
}
final List<Proxy> _proxies;
@override@JsonKey() List<Proxy> get proxies {
if (_proxies is EqualUnmodifiableListView) return _proxies;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_proxies);
}
// @JsonKey(name: 'rule-providers', fromJson: _genRuleProviders)
// @Default([])
// List<RuleProvider> ruleProvider,
// @JsonKey(name: 'sub-rules', fromJson: _genSubRules)
// @Default([])
// List<SubRule> subRules,
final Map<String, String> _proxyTypeMap;
// @JsonKey(name: 'rule-providers', fromJson: _genRuleProviders)
// @Default([])
// List<RuleProvider> ruleProvider,
// @JsonKey(name: 'sub-rules', fromJson: _genSubRules)
// @Default([])
// List<SubRule> subRules,
@override@JsonKey() Map<String, String> get proxyTypeMap {
if (_proxyTypeMap is EqualUnmodifiableMapView) return _proxyTypeMap;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_proxyTypeMap);
}
/// Create a copy of ClashConfig
/// with the given fields replaced by the non-null parameter values.
@@ -3471,16 +3774,16 @@ Map<String, dynamic> toJson() {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ClashConfig&&const DeepCollectionEquality().equals(other._proxyGroups, _proxyGroups)&&const DeepCollectionEquality().equals(other._rules, _rules));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ClashConfig&&const DeepCollectionEquality().equals(other._proxyGroups, _proxyGroups)&&const DeepCollectionEquality().equals(other._rules, _rules)&&const DeepCollectionEquality().equals(other._proxies, _proxies)&&const DeepCollectionEquality().equals(other._proxyTypeMap, _proxyTypeMap));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_proxyGroups),const DeepCollectionEquality().hash(_rules));
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_proxyGroups),const DeepCollectionEquality().hash(_rules),const DeepCollectionEquality().hash(_proxies),const DeepCollectionEquality().hash(_proxyTypeMap));
@override
String toString() {
return 'ClashConfig(proxyGroups: $proxyGroups, rules: $rules)';
return 'ClashConfig(proxyGroups: $proxyGroups, rules: $rules, proxies: $proxies, proxyTypeMap: $proxyTypeMap)';
}
@@ -3491,7 +3794,7 @@ abstract mixin class _$ClashConfigCopyWith<$Res> implements $ClashConfigCopyWith
factory _$ClashConfigCopyWith(_ClashConfig value, $Res Function(_ClashConfig) _then) = __$ClashConfigCopyWithImpl;
@override @useResult
$Res call({
@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups,@JsonKey(fromJson: _genRule) List<Rule> rules
@JsonKey(name: 'proxy-groups') List<ProxyGroup> proxyGroups,@JsonKey(fromJson: _genRule) List<Rule> rules, List<Proxy> proxies, Map<String, String> proxyTypeMap
});
@@ -3508,11 +3811,13 @@ class __$ClashConfigCopyWithImpl<$Res>
/// Create a copy of ClashConfig
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? proxyGroups = null,Object? rules = null,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? proxyGroups = null,Object? rules = null,Object? proxies = null,Object? proxyTypeMap = null,}) {
return _then(_ClashConfig(
proxyGroups: null == proxyGroups ? _self._proxyGroups : proxyGroups // ignore: cast_nullable_to_non_nullable
as List<ProxyGroup>,rules: null == rules ? _self._rules : rules // ignore: cast_nullable_to_non_nullable
as List<Rule>,
as List<Rule>,proxies: null == proxies ? _self._proxies : proxies // ignore: cast_nullable_to_non_nullable
as List<Proxy>,proxyTypeMap: null == proxyTypeMap ? _self._proxyTypeMap : proxyTypeMap // ignore: cast_nullable_to_non_nullable
as Map<String, String>,
));
}

View File

@@ -63,6 +63,18 @@ const _$GroupTypeEnumMap = {
GroupType.Relay: 'Relay',
};
_Proxy _$ProxyFromJson(Map<String, dynamic> json) => _Proxy(
name: json['name'] as String,
type: json['type'] as String,
now: json['now'] as String?,
);
Map<String, dynamic> _$ProxyToJson(_Proxy instance) => <String, dynamic>{
'name': instance.name,
'type': instance.type,
'now': instance.now,
};
_RuleProvider _$RuleProviderFromJson(Map<String, dynamic> json) =>
_RuleProvider(name: json['name'] as String);
@@ -321,12 +333,24 @@ _ClashConfig _$ClashConfigFromJson(Map<String, dynamic> json) => _ClashConfig(
.toList() ??
const [],
rules: json['rules'] == null ? const [] : _genRule(json['rules'] as List?),
proxies:
(json['proxies'] as List<dynamic>?)
?.map((e) => Proxy.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
proxyTypeMap:
(json['proxyTypeMap'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
) ??
const {},
);
Map<String, dynamic> _$ClashConfigToJson(_ClashConfig instance) =>
<String, dynamic>{
'proxy-groups': instance.proxyGroups,
'rules': instance.rules,
'proxies': instance.proxies,
'proxyTypeMap': instance.proxyTypeMap,
};
_PatchClashConfig _$PatchClashConfigFromJson(Map<String, dynamic> json) =>

View File

@@ -3356,275 +3356,6 @@ as String,
}
/// @nodoc
mixin _$Proxy {
String get name; String get type; String? get now;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ProxyCopyWith<Proxy> get copyWith => _$ProxyCopyWithImpl<Proxy>(this as Proxy, _$identity);
/// Serializes this Proxy to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is Proxy&&(identical(other.name, name) || other.name == name)&&(identical(other.type, type) || other.type == type)&&(identical(other.now, now) || other.now == now));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,name,type,now);
@override
String toString() {
return 'Proxy(name: $name, type: $type, now: $now)';
}
}
/// @nodoc
abstract mixin class $ProxyCopyWith<$Res> {
factory $ProxyCopyWith(Proxy value, $Res Function(Proxy) _then) = _$ProxyCopyWithImpl;
@useResult
$Res call({
String name, String type, String? now
});
}
/// @nodoc
class _$ProxyCopyWithImpl<$Res>
implements $ProxyCopyWith<$Res> {
_$ProxyCopyWithImpl(this._self, this._then);
final Proxy _self;
final $Res Function(Proxy) _then;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? name = null,Object? type = null,Object? now = freezed,}) {
return _then(_self.copyWith(
name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,now: freezed == now ? _self.now : now // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// Adds pattern-matching-related methods to [Proxy].
extension ProxyPatterns on Proxy {
/// 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( _Proxy value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_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?>(TResult Function( _Proxy value) $default,){
final _that = this;
switch (_that) {
case _Proxy():
return $default(_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( _Proxy value)? $default,){
final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_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( String name, String type, String? now)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_that.name,_that.type,_that.now);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?>(TResult Function( String name, String type, String? now) $default,) {final _that = this;
switch (_that) {
case _Proxy():
return $default(_that.name,_that.type,_that.now);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( String name, String type, String? now)? $default,) {final _that = this;
switch (_that) {
case _Proxy() when $default != null:
return $default(_that.name,_that.type,_that.now);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _Proxy implements Proxy {
const _Proxy({required this.name, required this.type, this.now});
factory _Proxy.fromJson(Map<String, dynamic> json) => _$ProxyFromJson(json);
@override final String name;
@override final String type;
@override final String? now;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ProxyCopyWith<_Proxy> get copyWith => __$ProxyCopyWithImpl<_Proxy>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ProxyToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Proxy&&(identical(other.name, name) || other.name == name)&&(identical(other.type, type) || other.type == type)&&(identical(other.now, now) || other.now == now));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,name,type,now);
@override
String toString() {
return 'Proxy(name: $name, type: $type, now: $now)';
}
}
/// @nodoc
abstract mixin class _$ProxyCopyWith<$Res> implements $ProxyCopyWith<$Res> {
factory _$ProxyCopyWith(_Proxy value, $Res Function(_Proxy) _then) = __$ProxyCopyWithImpl;
@override @useResult
$Res call({
String name, String type, String? now
});
}
/// @nodoc
class __$ProxyCopyWithImpl<$Res>
implements _$ProxyCopyWith<$Res> {
__$ProxyCopyWithImpl(this._self, this._then);
final _Proxy _self;
final $Res Function(_Proxy) _then;
/// Create a copy of Proxy
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? name = null,Object? type = null,Object? now = freezed,}) {
return _then(_Proxy(
name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,now: freezed == now ? _self.now : now // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
mixin _$Group {

View File

@@ -158,18 +158,6 @@ Map<String, dynamic> _$TrafficToJson(_Traffic instance) => <String, dynamic>{
'down': instance.down,
};
_Proxy _$ProxyFromJson(Map<String, dynamic> json) => _Proxy(
name: json['name'] as String,
type: json['type'] as String,
now: json['now'] as String?,
);
Map<String, dynamic> _$ProxyToJson(_Proxy instance) => <String, dynamic>{
'name': instance.name,
'type': instance.type,
'now': instance.now,
};
_Group _$GroupFromJson(Map<String, dynamic> json) => _Group(
type: $enumDecode(_$GroupTypeEnumMap, json['type']),
all:

View File

@@ -2498,7 +2498,7 @@ final class ClashConfigProvider
}
}
String _$clashConfigHash() => r'3987f6aee1131fe9b3978b914372b04ca2ae773c';
String _$clashConfigHash() => r'f7da0ec3a29379f6192c1206d2cd7535b45fab5e';
final class ClashConfigFamily extends $Family
with $FunctionalFamilyOverride<FutureOr<ClashConfig>, int> {

View File

@@ -682,7 +682,14 @@ Future<Script?> script(Ref ref, int? scriptId) async {
Future<ClashConfig> clashConfig(Ref ref, int profileId) async {
final configMap = await coreController.getConfig(profileId);
final clashConfig = ClashConfig.fromJson(configMap);
return clashConfig;
final Map<String, String> proxyTypeMap = {};
for (final proxy in clashConfig.proxies) {
proxyTypeMap[proxy.name] = proxy.type;
}
for (final proxyGroup in clashConfig.proxyGroups) {
proxyTypeMap[proxyGroup.name] = proxyGroup.type.value;
}
return clashConfig.copyWith(proxyTypeMap: proxyTypeMap);
}
@riverpod

View File

@@ -23,9 +23,12 @@ class _CustomProxyGroupsView extends ConsumerWidget {
maxWidth: 400,
),
builder: (context) {
return ProxyGroupProvider(
proxyGroup: proxyGroup,
child: _EditProxyGroupNestedSheet(),
return ProfileIdProvider(
profileId: profileId,
child: ProxyGroupProvider(
proxyGroup: proxyGroup,
child: _EditProxyGroupNestedSheet(),
),
);
},
);
@@ -254,9 +257,11 @@ class _EditProxyGroupViewState extends ConsumerState<_EditProxyGroupView> {
}
void _handleToProxiesView() {
Navigator.of(
context,
).push(PagedSheetRoute(builder: (context) => _EditProxiesView()));
Navigator.of(context).push(
PagedSheetRoute(
builder: (context) => _EditProxiesView(_proxyGroup.proxies ?? []),
),
);
}
void _handleToProvidersView() {}
@@ -547,16 +552,27 @@ class _EditProxyGroupViewState extends ConsumerState<_EditProxyGroupView> {
}
}
class _EditProxiesView extends StatefulWidget {
const _EditProxiesView();
class _EditProxiesView extends ConsumerStatefulWidget {
final List<String> proxyNames;
const _EditProxiesView(this.proxyNames);
@override
State<_EditProxiesView> createState() => _EditProxiesViewState();
ConsumerState<_EditProxiesView> createState() => _EditProxiesViewState();
}
class _EditProxiesViewState extends State<_EditProxiesView> {
class _EditProxiesViewState extends ConsumerState<_EditProxiesView> {
@override
Widget build(BuildContext context) {
final profileId = ProfileIdProvider.of(context)!.profileId;
final proxyNames = widget.proxyNames;
final proxyTypeMap =
ref.watch(
clashConfigProvider(
profileId,
).select((state) => state.value?.proxyTypeMap),
) ??
{};
final isBottomSheet =
SheetProvider.of(context)?.type == SheetType.bottomSheet;
return SizedBox(
@@ -567,11 +583,9 @@ class _EditProxiesViewState extends State<_EditProxiesView> {
title: '选择代理',
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(child: SizedBox(height: 16)),
SliverPadding(
padding: EdgeInsets.symmetric(
horizontal: 16,
vertical: 0,
).copyWith(top: 16),
padding: EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: CommonCard(
radius: 20,
@@ -584,6 +598,67 @@ class _EditProxiesViewState extends State<_EditProxiesView> {
),
),
),
SliverToBoxAdapter(child: SizedBox(height: 8)),
SliverPadding(
padding: EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: InfoHeader(
info: Info(label: '节点'),
actions: [
CommonMinFilledButtonTheme(
child: FilledButton.tonal(
onPressed: () {},
child: Text('添加'),
),
),
],
),
),
),
SliverReorderableList(
itemBuilder: (_, index) {
final proxyName = proxyNames[index];
return Container(
key: Key(proxyName),
margin: EdgeInsets.symmetric(vertical: 2, horizontal: 16),
color: Colors.transparent,
child: Row(
spacing: 8,
children: [
Flexible(
child: CommonCard(
radius: 18,
onPressed: () {},
child: ListTile(
leading: CommonMinIconButtonTheme(
child: IconButton.filledTonal(
onPressed: () {},
icon: Icon(Icons.remove, size: 18),
padding: EdgeInsets.zero,
),
),
minTileHeight:
32 + globalState.measure.bodyMediumHeight,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
),
title: Text(proxyName),
subtitle: Text(proxyTypeMap[proxyName]!),
),
),
),
],
),
);
},
itemExtent:
24 +
globalState.measure.bodyMediumHeight +
globalState.measure.bodyLargeHeight,
itemCount: proxyNames.length,
onReorder: (int oldIndex, int newIndex) {},
),
SliverToBoxAdapter(child: SizedBox(height: 16)),
],
),
),

View File

@@ -1,8 +1,8 @@
// ignore_for_file: deprecated_member_use
import 'package:collection/collection.dart';
import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/controller.dart';
import 'package:fl_clash/core/controller.dart';
import 'package:fl_clash/database/database.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/features/overwrite/rule.dart';
@@ -15,6 +15,7 @@ import 'package:fl_clash/views/profiles/preview.dart';
import 'package:fl_clash/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:reorderable_grid/reorderable_grid.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
part 'custom.dart';

View File

@@ -1,3 +1,5 @@
// ignore_for_file: deprecated_member_use
part of 'overwrite.dart';
class _ScriptContent extends ConsumerWidget {

View File

@@ -3,6 +3,7 @@ import 'dart:math';
import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/controller.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/models/clash_config.dart';
import 'package:fl_clash/models/common.dart';
import 'package:fl_clash/providers/providers.dart';
import 'package:fl_clash/widgets/widgets.dart';