Turn to federated plugin
This commit is contained in:
38
packages/moxdns_android/lib/moxdns_android.dart
Normal file
38
packages/moxdns_android/lib/moxdns_android.dart
Normal 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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user