gpt4 book ai didi

flutter - Dart 错误 : error: import of dart:mirrors is not supported in the current Dart runtime

转载 作者:行者123 更新时间:2023-12-03 02:53:04 24 4
gpt4 key购买 nike

我目前正在尝试使用 Flutter 制作一些移动代码。我正在尝试使用 gcloud 库 dart 将数据发布/订阅到 GCP Cloud Pub/Sub。这是 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;
}

以下是 pubspec.yaml 上的依赖项:
dependencies:
flutter:
sdk: flutter

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


尝试调试代码时,出现以下错误:
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 文件中导入了“package:json_annotation/json_annotation.dart”和“package:json_serializable/json_serializable.dart”。删除 json_serializable 包解决了上述错误。

关于flutter - Dart 错误 : error: import of dart:mirrors is not supported in the current Dart runtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58472589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com