prepare json

This commit is contained in:
open-trade 2020-11-16 02:12:37 +08:00
parent da7a71cd81
commit b02aec4255
2 changed files with 19 additions and 0 deletions

View File

@ -23,10 +23,13 @@ class MyTheme {
}
typedef F1 = void Function(Pointer<Utf8>);
typedef F2 = Pointer<Utf8> Function();
// https://juejin.im/post/6844903864852807694
class FfiModel with ChangeNotifier {
F1 _connectRemote;
F2 _getPeers;
F1 _freeCString;
FfiModel() {
initialzeFFI();
@ -40,6 +43,17 @@ class FfiModel with ChangeNotifier {
_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 {
final dylib = Platform.isAndroid
? DynamicLibrary.open('librustdesk.so')
@ -48,6 +62,9 @@ class FfiModel with ChangeNotifier {
void Function(Pointer<Utf8>)>('initialize');
_connectRemote = dylib
.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;
initialize(Utf8.toUtf8(dir));
notifyListeners();

View File

@ -43,6 +43,7 @@ class _HomePageState extends State<HomePage> {
}
Widget getSearchBarUI() {
var id = ffi.getId();
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
@ -65,6 +66,7 @@ class _HomePageState extends State<HomePage> {
child: Container(
padding: const EdgeInsets.only(left: 16, right: 16),
child: TextFormField(
initialValue: id,
style: TextStyle(
fontFamily: 'WorkSans',
fontWeight: FontWeight.bold,