-
Notifications
You must be signed in to change notification settings - Fork 0
Dart and Flutter Integration
v2rayroot edited this page Jun 14, 2026
·
1 revision
import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetStatusNative = Pointer<Utf8> Function();
typedef GetStatusDart = Pointer<Utf8> Function();
typedef FreeNative = Void Function(Pointer<Utf8>);
typedef FreeDart = void Function(Pointer<Utf8>);
final library = DynamicLibrary.open('xray-windows-amd64.dll');
final getStatus =
library.lookupFunction<GetStatusNative, GetStatusDart>('GetStatus');
final freeCString =
library.lookupFunction<FreeNative, FreeDart>('FreeCString');
String take(Pointer<Utf8> pointer) {
if (pointer == nullptr) {
throw StateError('Unexpected null native string');
}
try {
return pointer.toDartString();
} finally {
freeCString(pointer);
}
}Run latency tests, geo downloads, validation of large configurations, and other blocking work away from the Flutter UI isolate.
Bundle the correct DLL/SO for each target architecture and resolve it by an application-controlled absolute path.