import "dart:async"; import "dart:collection"; import "package:flutter/services.dart"; class SrvRecord { final String target; final int port; final int priority; final int weight; const SrvRecord({ required this.target, required this.port, required this.priority, required this.weight }); } class Moxdns { static const MethodChannel _channel = MethodChannel("moxdns"); static Future> srvQuery(String domain, bool dnssec) async { try { final List results = await _channel.invokeMethod("srvQuery", [ domain, dnssec ]); final records = List.empty(growable: true); for (var record in results) { if (record == null) { continue; } final rr = Map.from(record); records.add(SrvRecord( target: rr["target"]!, port: int.parse(rr["port"]!), priority: int.parse(rr["priority"]!), weight: int.parse(rr["weight"]!) )); } return records; } on PlatformException catch(e) { return const []; } return const []; } }