我想使用mongo存储我的应用数据,但是当我尝试await db.open()
时,控制台上会出现此错误:
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (11408): type 'Future<dynamic>' is not a subtype of type 'Future<bool>' where
E/flutter (11408): Future is from dart:async
E/flutter (11408): Future is from dart:async
E/flutter (11408): bool is from dart:core
E/flutter (11408):
E/flutter (11408): #0 _Connection.connect (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection.dart:73:22)
E/flutter (11408): #1 _ConnectionManager._connect (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:23:22)
E/flutter (11408): <asynchronous suspension>
E/flutter (11408): #2 _ConnectionManager.open.<anonymous closure> (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:58:14)
E/flutter (11408): #3 Future.forEach.<anonymous closure> (dart:async/future.dart:484:26)
E/flutter (11408): #4 Future.doWhile.<anonymous closure> (dart:async/future.dart:526:26)
E/flutter (11408): #5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter (11408): #6 _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1355:26)
E/flutter (11408): #7 Future.doWhile (dart:async/future.dart:541:18)
E/flutter (11408): #8 Future.forEach (dart:async/future.dart:482:12)
E/flutter (11408): #9 _ConnectionManager.open (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:56:19)
E/flutter (11408): #10 Db.open.<anonymous closure> (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/database/db.dart:252:33)
E/flutter (11408): #11 new Future.sync (dart:async/future.dart:222:31)
E/flutter (11408): #12 Db.open (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/database/db.dart:239:16)
E/flutter (11408): #13 main (file:///F:/Jamil/WORKSHOP/MY-PRACTICE/FLUTTER/FLUTTERMONGO/simplecrud/lib/main.dart:6:6)
E/flutter (11408): <asynchronous suspension>
E/flutter (11408): #14 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
E/flutter (11408): #15 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
E/flutter (11408): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (11408): type '(MongoReplyMessage) => void' is not a subtype of type '(dynamic) => void'
E/flutter (11408): #0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1114:29)
E/flutter (11408): #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (11408): #2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
这是我写的用于在mlab和app之间打开连接的简单代码:
import 'package:mongo_dart/mongo_dart.dart';
void main() async {
print('hello');
Db db = new Db('mongodb://<myusername><mypassword>@ds147659.mlab.com:47659/simple-crud');
db.open().then((success) {
if (success) print('connected');
});
}
任何想法,先生?
答案 0 :(得分:1)
这是由于最新的扑克更新beta2。 请查看此blog by flutter
看起来你的项目和Mongo插件的版本不匹配。
Mongo的最新插件于2017年10月24日更新。
已有issue on their git。你可以跟踪它。
同时,根据this issue: 您可以尝试从
更改插件代码Future<bool> get isOn => _channel.invokeMethod('isOn');
到
Future<bool> get isOn async {
final bool isOn = await _channel.invokeMethod('isOn');
return isOn;
}
注意:以上只是一个示例,请检查插件dart文件以获取正确的更改功能。