Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime

。_饼干妹妹 提交于 2019-12-23 04:34:20

问题


I'm currently trying to make some mobile code with Flutter. I'm trying to publish/subscribe data to GCP Cloud Pub/Sub using gcloud library dart. Here is the code for the 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;
}

Here are the denpendencies on the pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

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

When trying to debug the code I get the following errors:

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.

回答1:


Unfortunately the glcoud package for dart is not compatible with flutter (or web) due to the mirror package.

I suggest you to open an issue on the github repository about supporting gcloud pub/sub on flutter. https://github.com/dart-lang/gcloud/issues/new

I can also check the googleapis package which has a pub/sub implementation that might fit your needs. https://pub.dev/documentation/googleapis/latest/googleapis.pubsub.v1/googleapis.pubsub.v1-library.html. (use by glcoud package)



来源:https://stackoverflow.com/questions/58472589/dart-error-error-import-of-dartmirrors-is-not-supported-in-the-current-dart-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!