我正在尝试将graphql_flutter (https://pub.dev/packages/graphql_flutter) 用于我的MVVM架构。(https://stacked.filledstacks.com/docs/getting-started/overview) 当我尝试运行代码时,从graphql_flutter包中得到以下错误:
`../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/graphql-5.1.2/lib/src/links/websocket_link/websocket_client.dart:577:7: 错误:非抽象类 'GraphQLWebSocketChannel' 缺少这些成员的实现:
- WebSocketChannel.ready 请尝试
- 提供一个实现,
- 继承一个超类或混入的实现,
- 将该类标记为抽象类, 或者
- 提供一个'noSuchMethod'的实现。
class GraphQLWebSocketChannel extends StreamChannelMixin<dynamic> ^^^^^^^^^^^^^^^^^^^^^^^ ../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-2.3.0/lib/src/channel.dart:56:22: 上下文:在此定义 'WebSocketChannel.ready'。 final Future<void> ready = Future.value();`
以下是我的主要dart文件中的代码。 只要我导入了该软件包,我就会收到错误信息。
import 'package:flutter/material.dart';
import 'package:testing/app/app.locator.dart';
import 'package:testing/ui/common/app_colors.dart';
import 'package:testing/ui/setup/setup_bottom_sheet_ui.dart';
import 'package:testing/ui/setup/setup_dialog_ui.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'app/app.router.dart';
void main() {
setupLocator();
setupDialogUi();
setupBottomSheetUi();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
HttpLink httpLink = HttpLink("https://api.github.com/graphql");
AuthLink authLink = AuthLink(
getToken: () async => 'Bearer PERSONAL_ACCESS_TOKEN',
);
Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> qlClient = ValueNotifier(
GraphQLClient(
link: link,
// The default store is the InMemoryStore, which does NOT persist to disk
cache: GraphQLCache(store: HiveStore()),
),
);
return GraphQLProvider(
client: qlClient,
child: MaterialApp(
title: 'Flutter Demo',
theme: Theme.of(context).copyWith(
primaryColor: kcBackgroundColor,
focusColor: kcPrimaryColor,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Colors.black,
),
),
initialRoute: Routes.startupView,
onGenerateRoute: StackedRouter().onGenerateRoute,
navigatorKey: StackedService.navigatorKey,
navigatorObservers: [
StackedService.routeObserver,
],
));
}
}