class TunConfig { final bool enable; final String stack; final List dnsHijack; final bool autoRoute; final bool autoDetectInterface; TunConfig({ required this.enable, required this.stack, required this.dnsHijack, required this.autoRoute, required this.autoDetectInterface, }); factory TunConfig.fromMap(Map map) { return TunConfig( enable: map['enable'] ?? false, stack: map['stack'] ?? 'system', dnsHijack: List.from(map['dns-hijack'] ?? []), autoRoute: map['auto-route'] ?? false, autoDetectInterface: map['auto-detect-interface'] ?? false, ); } Map toJson() { return { 'enable': enable, 'stack': stack, 'dns-hijack': dnsHijack, 'auto-route': autoRoute, 'auto-detect-interface': autoDetectInterface, }; } String toYaml() { return ''' tun: enable: $enable stack: $stack dns-hijack: ${dnsHijack.map((item) => ' - $item').join('\n')} auto-route: $autoRoute auto-detect-interface: $autoDetectInterface '''; } }