flutter实现promise中resolve(RxJava中emiter.onSucess("result"))功能
BehaviorSubject openCameraController = BehaviorSubject();
BridgeChannel _openCamera() {
print('- - - - - - - - - - - - - - - - - - > _openCamera() ');
return BridgeChannel(
name: 'openCamera',
onBridgeHandler: (dataFromJs) async {
print('- - - - - - - - - - - - - - - - - - > 111 '+dataFromJs);
EventBus().post(OpenCameraEvent(dataFromJs));
print('- - - - - - - - - - - - - - - - - -> 222 ');
String str = await doSome();
print(" - - - - - - - - - - - - - - - - - - > 555 "+str);
return str;
}
);
}
Future<String> doSome() async {
// 注意Future的范型不正确的话,await Future完不会生成String
Future<String> future = new Future(() => "");
openCameraController.listen((resul) async {
future.then((_) => resul);
});
return future;
}