feat: implement dialog callback

This commit is contained in:
Kingtous
2023-05-08 12:34:19 +08:00
parent 19f81ad317
commit 77fa807b57
55 changed files with 734 additions and 554 deletions

View File

@@ -1,5 +1,9 @@
import 'dart:convert';
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter_hbb/plugin/utils/dialogs.dart';
abstract class NativeHandler {
bool onEvent(Map<String, dynamic> evt);
}
@@ -37,7 +41,13 @@ class NativeUiHandler extends NativeHandler {
}
void onSelectPeers(OnSelectPeersCallbackDart cb, int userData) async {
// TODO: design a UI interface to pick peers.
cb(0, Pointer.fromAddress(0), 0, Pointer.fromAddress(userData));
showPeerSelectionDialog(onPeersCallback: (peers) {
String json = jsonEncode(<String, dynamic> {
"peers": peers
});
final native = json.toNativeUtf8();
cb(0, native.cast(), native.length, Pointer.fromAddress(userData));
malloc.free(native);
});
}
}