首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Graphql-Flutter问题:配置项目':connectivity‘时出现问题

Graphql-Flutter问题:配置项目':connectivity‘时出现问题
EN

Stack Overflow用户
提问于 2020-05-08 15:32:11
回答 1查看 860关注 0票数 1

我对flutter有一个问题:在此之前,我在windows10中编写了我的flutter应用程序,我对它没有任何问题。但是自从我切换到ubuntu 20.04之后,我遇到了一些flutter的问题。

当我启动简单的默认flutter应用程序时,它工作得很好,没有任何问题,但当我创建一个简单的应用程序,使用graphql-flutter包发送查询时,就在按下F5运行程序后,我遇到了这个错误消息:

代码语言:javascript
复制
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':connectivity'.
> Could not resolve all artifacts for configuration ':connectivity:classpath'.
   > Could not find crash.jar (com.android.tools.analytics-library:crash:26.3.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/crash/26.3.0/crash-26.3.0.jar
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':connectivity' of type org.gradle.api.Project.
   > Could not find method implementation() for arguments [project ':connectivity_macos'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
Exception: Gradle task assembleDebug failed with exit code 1

我的pubspec.yaml文件包含:

代码语言:javascript
复制
dependencies:
  flutter:
    sdk: flutter
  graphql_flutter: ^3.0.1

我的flutter doctor的运行结果是:

代码语言:javascript
复制
hossein@MHT:~$ flutter doctor -v
[✓] Flutter (Channel stable, v1.17.0, on Linux, locale en_US.UTF-8)
    • Flutter version 1.17.0 at /home/hossein/Development/flutter
    • Framework revision e6b34c2b5c (6 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/hossein/Android/Sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /snap/android-studio/88/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Android Studio (version 3.6)
    • Android Studio at /snap/android-studio/88/android-studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

• No issues found!

*更新:我再次检查了我的代码,当我从我的代码中删除graphql-flutter包以及所有相关的窗口小部件和函数时,问题并不存在,并且我的代码构建和运行成功。graphql-flutter软件包和flutter sdk或gradle之间似乎存在问题。但我不知道如何才能克服这个错误。请帮帮我。

出现错误的graphql-flutter包的颤动代码是:

代码语言:javascript
复制
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GraphQLProvider(
      client: Config.initailizeClient(),
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          appBarTheme: AppBarTheme(color: Colors.grey[700]),
        ),
        home: HomePage(),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String query = '''
    query Products(\$name: String!) {
      products(name:\$name) {
        id
        name
        price
      }
    }
  ''';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Directionality(
        textDirection: TextDirection.rtl,
        child: Query(
          options: QueryOptions(
            // this is the query string you just created
            documentNode: gql(query),
            variables: {
              "name": "بوت",
            },
          ),
          builder: (QueryResult result,
              {VoidCallback refetch, FetchMore fetchMore}) {
            if (result.hasException) {
              return Text(result.exception.toString());
            }

            if (result.loading) {
              return Center(child: CircularProgressIndicator());
            }
            return Container(
              margin: EdgeInsets.only(right: 8.0, left: 8.0),
              child: ListView.builder(
                itemCount: result.data["products"].length,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(
                    onTap: () {},
                    title: Container(
                      padding: EdgeInsets.all(5.0),
                      height: 35.0,
                      child: Text(
                        result.data["products"][index]["name"],
                        style: TextStyle(
                            color: Colors.grey[850],
                            fontFamily: 'Yekan',
                            fontSize: 18.0),
                      ),
                    ),
                    subtitle: Text(
                      result.data["products"][index]["price"],
                      style: TextStyle(
                          color: Colors.redAccent,
                          fontFamily: 'Yekan',
                          fontSize: 15.0),
                    ),
                    trailing: Icon(Icons.arrow_right),
                    contentPadding: EdgeInsets.only(top: 3.5, bottom: 3.5),
                  );
                },
              ),
            );
          },
        ),
      ),
    );
  }
}

class Config {
  static final HttpLink link = HttpLink(
    headers: <String, String>{
      'Authorization': 'JWT ${Env.jwtToken}',
      'Content-Type': 'application/json'
    },
    uri: Env.graphqlEndpointURL,
  );

  static ValueNotifier<GraphQLClient> initailizeClient() {
    ValueNotifier<GraphQLClient> client = ValueNotifier(
      GraphQLClient(
        cache: InMemoryCache(),
        link: link,
      ),
    );
    return client;
  }
}

当我删除graphql-flutter包功能并简化我的代码时,成功构建和运行的代码如下所示:

代码语言:javascript
复制
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        appBarTheme: AppBarTheme(color: Colors.grey[700]),
      ),
      home: SecondPage(),
    );
  }
}

class SecondPage extends StatefulWidget {
  @override
  _SecondPageState createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Text('salam'),
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-05-09 08:10:03

这可能是因为connectivity graphql_flutter使用的版本存在一些问题。

首先尝试flutter clean,如果不起作用,请尝试覆盖pubspec.yaml中的connectivity

代码语言:javascript
复制
dependency_overrides:
  connectivity: 0.4.8+5
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61674195

复制
相关文章

相似问题

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