Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Dart错误:错误:当前Dart运行时不支持导入Dart:镜像_Flutter_Dart_Google Cloud Platform_Gcloud_Google Cloud Pubsub - Fatal编程技术网

Flutter Dart错误:错误:当前Dart运行时不支持导入Dart:镜像

Flutter Dart错误:错误:当前Dart运行时不支持导入Dart:镜像,flutter,dart,google-cloud-platform,gcloud,google-cloud-pubsub,Flutter,Dart,Google Cloud Platform,Gcloud,Google Cloud Pubsub,我目前正在尝试用Flutter制作一些移动代码。我正在尝试使用gcloud library dart向GCP Cloud发布/订阅数据。以下是main.dart的代码: 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:gc

我目前正在尝试用Flutter制作一些移动代码。我正在尝试使用gcloud library dart向GCP Cloud发布/订阅数据。以下是main.dart的代码:

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;
}
尝试调试代码时,我遇到以下错误:

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.

不幸的是,dart的glcoud包由于镜像包而与颤振(或web)不兼容

我建议您在github存储库上打开一个关于在Flatter上支持gcloud pub/sub的问题。

我还可以检查包,它有一个pub/sub实现,可能适合您的需要。
. (由glcoud包使用)

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

在Flitter中不支持dart镜像。您对如何在Flitter中从cloud pubsub发布/订阅有何建议?我提出了同样的问题:
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.