首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dart错误:错误:当前Dart运行时不支持导入dart:mirrors

Dart错误:错误:当前Dart运行时不支持导入dart:mirrors
EN

Stack Overflow用户
提问于 2019-10-20 19:34:32
回答 2查看 5.8K关注 0票数 4

我目前正在尝试用Flutter编写一些移动代码。我正在尝试使用gcloud库dart将数据发布/订阅到GCP Cloud Pub/Sub。下面是main.dart的代码:

代码语言:javascript
复制
import 'dart:io';
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:http/http.dart' as http;
import 'package:gcloud/db.dart';
import 'package:gcloud/storage.dart';


import 'package:gcloud/pubsub.dart';
import 'package:gcloud/service_scope.dart' as ss;
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;

Future<int> main() async {

  // Read the service account credentials from the file.
var jsonCredentials = new File('path/file.json').readAsStringSync();
var credentials = new auth.ServiceAccountCredentials.fromJson(jsonCredentials);

// Get an HTTP authenticated client using the service account credentials.
var scopes = []    
    ..addAll(PubSub.SCOPES);
var client = await auth.clientViaServiceAccount(credentials, scopes);


// Instantiate objects to access Cloud Datastore, Cloud Storage
// and Cloud Pub/Sub APIs.
var pubsub = new PubSub(client, 'project-name');
ss.fork(() {
  // register the services in the new service scope.
  registerPubSubService(pubsub);

  // Run application using these services.
});

var topic = await pubsub.createTopic('flutter');
await topic.publishString('coba publish dr flutter');

var subscription =
    await pubsub.createSubscription('sub_flutter', 'flutter');
var pullEvent = await subscription.pull();
print(pullEvent.message.asString);
await pullEvent.acknowledge();

  return 0;
}

以下是对pubspec.yaml的依赖关系:

代码语言:javascript
复制
dependencies:
  flutter:
    sdk: flutter

  googleapis: ^0.54.0
  googleapis_beta: ^0.49.0
  googleapis_auth: ^0.2.10
  gcloud: ^0.6.3

当尝试调试代码时,我得到以下错误:

代码语言:javascript
复制
Launching lib\main.dart on vivo 1918 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
E/flutter (20586): [ERROR:flutter/shell/common/shell.cc(178)] Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime
E/flutter (20586): [ERROR:flutter/shell/common/engine.cc(188)] Could not prepare to run the isolate.
E/flutter (20586): [ERROR:flutter/shell/common/engine.cc(127)] Engine not prepare and launch isolate.
E/flutter (20586): [ERROR:flutter/shell/common/shell.cc(407)] Could not launch engine with configuration.
EN

回答 2

Stack Overflow用户

发布于 2020-09-02 17:33:18

在我的示例中,对于其中一个项目,我在dart文件中导入了'package:json_annotation/json_annotation.dart‘和'package:json_serializable/json_serializable.dart’。删除json_serializable包解决了上述错误。

票数 13
EN

Stack Overflow用户

发布于 2019-10-21 16:22:56

不幸的是,由于镜像包的原因,用于dart的glcoud包与flutter (或web)不兼容。

我建议你在github存储库上打开一个关于在flutter上支持gcloud pub/sub的问题。https://github.com/dart-lang/gcloud/issues/new

我还可以查看googleapis包,它有一个可能满足您需求的发布/订阅实现。https://pub.dev/documentation/googleapis/latest/googleapis.pubsub.v1/googleapis.pubsub.v1-library.html。(由glcoud包使用)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58472589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档