Reputation: 1108
I have a problem with flutter:
before now, I wrote my flutter app in windows 10 and i had no problem with it. but since i switched to ubuntu 20.04, I encountered some problems with flutter.
when i start simple default flutter app it works very well without any problem, but when i make a simple app for using graphql-flutter package for sending a query, right after pressing F5 for running program i encountered this error message:
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
my pubspec.yaml file containg:
dependencies:
flutter:
sdk: flutter
graphql_flutter: ^3.0.1
and my flutter doctor running result is:
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!
*** update: I checked my code again, when i remove graphql-flutter package and all related widgets and functions from my code, the problem is not occure and my code build and run successfully. it seems there is a problem betwen graphql-flutter package and flutter sdk or gradle. but i dont know how can i overcome this error. please help me.
my flutter code with graphql-flutter package which made error is:
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;
}
}
and when i remove graphql-flutter package functionality and simplify my code which build and run successfully is looks like this :
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'),
),
);
}
}
Upvotes: 1
Views: 3069
Reputation: 508
It's been a while since you posted this question, but I'll provide an answer for others who might need it.
I encountered a similar issue in my Flutter project, which was previously building and running fine. One day, I decided to clean up unused packages and removed the connectivity package from the pubspec.yaml file. After that, the project failed to build.
I resolved the issue by re-adding the connectivity dependency to the pubspec file, and it started working again.
So, in your case, just add the connectivity dependency and error will be gone.
Upvotes: 2
Reputation: 944
This could be because of some issue with the version of connectivity
graphql_flutter
uses.
Try flutter clean
first, and if that doesn't work, try overriding connectivity
in your pubspec.yaml
:
dependency_overrides:
connectivity: 0.4.8+5
Upvotes: 1