prepare json
This commit is contained in:
parent
da7a71cd81
commit
b02aec4255
@ -23,10 +23,13 @@ class MyTheme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef F1 = void Function(Pointer<Utf8>);
|
typedef F1 = void Function(Pointer<Utf8>);
|
||||||
|
typedef F2 = Pointer<Utf8> Function();
|
||||||
|
|
||||||
// https://juejin.im/post/6844903864852807694
|
// https://juejin.im/post/6844903864852807694
|
||||||
class FfiModel with ChangeNotifier {
|
class FfiModel with ChangeNotifier {
|
||||||
F1 _connectRemote;
|
F1 _connectRemote;
|
||||||
|
F2 _getPeers;
|
||||||
|
F1 _freeCString;
|
||||||
|
|
||||||
FfiModel() {
|
FfiModel() {
|
||||||
initialzeFFI();
|
initialzeFFI();
|
||||||
@ -40,6 +43,17 @@ class FfiModel with ChangeNotifier {
|
|||||||
_connectRemote(Utf8.toUtf8(id));
|
_connectRemote(Utf8.toUtf8(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getId() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void peers() {
|
||||||
|
var p = _getPeers();
|
||||||
|
var x = Utf8.fromUtf8(p);
|
||||||
|
// https://github.com/brickpop/flutter-rust-ffi
|
||||||
|
_freeCString(p);
|
||||||
|
}
|
||||||
|
|
||||||
Future<Null> initialzeFFI() async {
|
Future<Null> initialzeFFI() async {
|
||||||
final dylib = Platform.isAndroid
|
final dylib = Platform.isAndroid
|
||||||
? DynamicLibrary.open('librustdesk.so')
|
? DynamicLibrary.open('librustdesk.so')
|
||||||
@ -48,6 +62,9 @@ class FfiModel with ChangeNotifier {
|
|||||||
void Function(Pointer<Utf8>)>('initialize');
|
void Function(Pointer<Utf8>)>('initialize');
|
||||||
_connectRemote = dylib
|
_connectRemote = dylib
|
||||||
.lookupFunction<Void Function(Pointer<Utf8>), F1>('connect_remote');
|
.lookupFunction<Void Function(Pointer<Utf8>), F1>('connect_remote');
|
||||||
|
_getPeers = dylib.lookupFunction<F2, F2>('get_peers');
|
||||||
|
_freeCString = dylib
|
||||||
|
.lookupFunction<Void Function(Pointer<Utf8>), F1>('rust_cstr_free');
|
||||||
final dir = (await getApplicationDocumentsDirectory()).path;
|
final dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
initialize(Utf8.toUtf8(dir));
|
initialize(Utf8.toUtf8(dir));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -43,6 +43,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget getSearchBarUI() {
|
Widget getSearchBarUI() {
|
||||||
|
var id = ffi.getId();
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0),
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -65,6 +66,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
|
initialValue: id,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontFamily: 'WorkSans',
|
fontFamily: 'WorkSans',
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user