- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我在 Flutter 中使用事件 channel 将信标数据从 Native SDK 返回到 Flutter。在最近的 Flutter 升级之前,它工作正常。现在,我收到以下错误。
type '(PlatformException) => void' is not a subtype of type '(Object) => FutureOr<dynamic>
具有以下堆栈跟踪:
#0 _registerErrorHandler (dart:async/async_error.dart:22:60)
#1 _BufferingStreamSubscription.onError (dart:async/stream_impl.dart:146:16)
#2 new _BufferingStreamSubscription (dart:async/stream_impl.dart:113:10)
#3 new _ControllerSubscription (dart:async/stream_controller.dart)
#4 new _BroadcastSubscription (dart:async/broadcast_stream_controller.dart)
#5 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:212:46)
#6 _ControllerStream._createSubscription (dart:async/stream_controller.dart:817:19)
#7 _StreamImpl.listen (dart:async/stream_impl.dart:466:9)
#8 _MyHomePageState.initPlatformState.<anonymous closure>.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:95:43)
#9 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#10 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#12 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#13 Future._complete (dart:async/future_impl.dart:467:7)
#14 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#15 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
<asynchronous suspension>
#16 _MyHomePageState.initPlatformState.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:89:24)
<asynchronous suspension>
#17 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#18 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#19 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#20 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#21 Future._complete (dart:async/future_impl.dart:467:7)
#22 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#23 User_Profile.getUser (package:flutter_poc/Models/User.dart)
<asynchronous suspension>
#24 _MyHomePageState.initPlatformState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:69:24)
<asynchronous suspension>
#25 _MyHomePageState.initState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:52:5)
#26 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3734:58)
#27 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
#28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
#29 Element.updateChild
这是我的 EventChannel 实现:
static const platform = const MethodChannel('samples.flutter.io/initialiseRanging');
static const stream =
const EventChannel('samples.flutter.io/ranging');
try {
await platform.invokeMethod('initialiseRanging').then((result){
print(result);
setState(() {
_currentValue = result;
});
stream.receiveBroadcastStream().listen(_onEvent, onError: _onError);
});
} on PlatformException catch (e) {
print( "{e.message}");
}
这就是 _onEvent
的方式和 _onError
功能实现。
void _onEvent(Object event) {
setState(() {
_currentValue = event.toString();
});
print(event);
}
void _onError(PlatformException error) {
print(error);
}
知道为什么会发生这种情况吗?
最佳答案
void _onError(PlatformException error) {
应该是
void _onError(Object error) {
即使您只对 PlatformException
感兴趣,或者即使这是迄今为止发生的唯一异常,也不意味着不能有其他异常。预期的处理函数需要匹配参数类型,而不仅仅是您预期的异常。
关于dart - 类型 '(PlatformException) => void' 不是类型 '(Object) => FutureOr<dynamic> Flutter 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49793193/
Dart 提供 FutureOr类,允许编写: FutureOr future; future = 42; // valid future = Future.value(42); // also va
将flutter项目升级到null-safety时出现如下错误 The name 'FutureOr' isn't a type, so it can't be used in an 'as'
我正在尝试从Future 类型检索数据,但出现此异常: Exception: type 'List' is not a subtype of type 'FutureOr' 这是返回Future 的方
我收到错误:类型“List”不是类型“FutureOr>”的子类型。我已经检查了数据类型,但似乎找不到错误的原因。 //getting the data from api call Future> _
我正在编写Flutter App,其中一项要求是脱机保存数据以在不连接互联网的情况下进行读取,但是当我从Sqflite的DB加载时出现问题,我收到此错误:type '_Type' is not a s
我在 AngularDart 中有一个类,如下所示: abstract class Validator { Map validate(AbstractControl c); } 仔细观察,这曾经是
在我的 Firebase 身份验证中,我遇到了错误: error: The argument type 'Null Function(FirebaseUser)' can't be assigned
我是 Dart/Flutter 的新手,我正在尝试获取使用网络服务的 future 结果: Future _readData() async { (...) http.Response res
我在 Flutter 中使用事件 channel 将信标数据从 Native SDK 返回到 Flutter。在最近的 Flutter 升级之前,它工作正常。现在,我收到以下错误。 type '(Pl
当我尝试解码 JSON 时,出现此错误: Expected a value of type 'FutureOr', but got one of type '_JsonMap' 这是我从 API 获取
我通过分步指南学习了 Flutter。因此,当我使用指南中的代码时 - 它运行良好,但当我尝试更改 JSON URL 时,出现错误。据我了解,JSON格式和jsonDecode的问题就是无法解码RIO
import 'package:flutter/material.dart'; import 'package:camera/camera.dart'; class Register
我正在编写一个 Flutter 插件,它从平台特定端发送一个 map 列表 (List>)。在平台特定方面,我使用默认消息编解码器发送这些对象。 // (example: Android side)
我似乎无法弄清楚如何解决此错误。以前这是可行的,但现在升级到Flutter Null Safety版本后会产生此错误: 我正在使用屏幕截图:ScreenshotController的^ 1.0.0-n
我正在尝试编译示例: https://github.com/dart-lang/googleapis_examples/blob/master/drive_upload_download_consol
我是一名优秀的程序员,十分优秀!