Turn to federated plugin

This commit is contained in:
2022-04-29 13:58:33 +02:00
parent 623555523a
commit 546f41bf87
68 changed files with 5673 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import "package:moxdns/moxdns.dart";
import "package:moxdns_platform_interface/moxdns_platform_interface.dart";
import "package:flutter/services.dart";
class MoxdnsAndroidPlugin extends MoxdnsPlatform {
final MethodChannel _channel;
MoxdnsAndroidPlugin() : _channel = MethodChannel("me.polynom.moxdns_android"), super();
static void registerWith() {
print("MoxdnsAndroidPlugin: Registering implementation");
MoxdnsPlugin.platform = MoxdnsAndroidPlugin();
}
@override
Future<List<SrvRecord>> srvQuery(String domain, bool dnssec) async {
try {
final List<dynamic> results = await _channel.invokeMethod("srvQuery", [ domain, dnssec ]);
final records = List<SrvRecord>.empty(growable: true);
for (var record in results) {
if (record == null) {
continue;
}
final rr = Map<String, String>.from(record);
records.add(SrvRecord(
rr["target"]!,
int.parse(rr["port"]!),
int.parse(rr["priority"]!),
int.parse(rr["weight"]!)
));
}
return records;
} on PlatformException catch(e) {
print("moxdns_android: $e");
return const [];
}
}
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'moxdns_android_platform_interface.dart';
/// An implementation of [MoxdnsAndroidPlatform] that uses method channels.
class MethodChannelMoxdnsAndroid extends MoxdnsAndroidPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('moxdns_android');
@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
}

View File

@@ -0,0 +1,29 @@
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'moxdns_android_method_channel.dart';
abstract class MoxdnsAndroidPlatform extends PlatformInterface {
/// Constructs a MoxdnsAndroidPlatform.
MoxdnsAndroidPlatform() : super(token: _token);
static final Object _token = Object();
static MoxdnsAndroidPlatform _instance = MethodChannelMoxdnsAndroid();
/// The default instance of [MoxdnsAndroidPlatform] to use.
///
/// Defaults to [MethodChannelMoxdnsAndroid].
static MoxdnsAndroidPlatform get instance => _instance;
/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [MoxdnsAndroidPlatform] when
/// they register themselves.
static set instance(MoxdnsAndroidPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
}
}