I was getting the below error in Flutter. I tried to remove and reinstall the GetX package from the pubspec.yaml
file, but it didn't work. I also ran the flutter clean
command, deleted the pubspec.lock
file, and restarted IDE several times, but it also didn't work.
Running Gradle task 'assembleDebug'...
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart:105:10: Error: 'translations' isn't an instance field of this class.
this.translations,
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart:216:15: Error: The getter 'translations' isn't defined for the class 'GetMaterialApp'.
- 'GetMaterialApp' is from 'package:get/get_navigation/src/root/get_material_app.dart' ('../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'translations'.
if (translations != null) {
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart:217:33: Error: The getter 'translations' isn't defined for the class 'GetMaterialApp'.
- 'GetMaterialApp' is from 'package:get/get_navigation/src/root/get_material_app.dart' ('../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'translations'.
Get.addTranslations(translations!.keys);
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_cupertino_app.dart:150:10: Error: 'translations' isn't an instance field of this class.
this.translations,
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_cupertino_app.dart:202:15: Error: The getter 'translations' isn't defined for the class 'GetCupertinoApp'.
- 'GetCupertinoApp' is from 'package:get/get_navigation/src/root/get_cupertino_app.dart' ('../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_cupertino_app.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'translations'.
if (translations != null) {
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_cupertino_app.dart:203:33: Error: The getter 'translations' isn't defined for the class 'GetCupertinoApp'.
- 'GetCupertinoApp' is from 'package:get/get_navigation/src/root/get_cupertino_app.dart' ('../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/get_navigation/src/root/get_cupertino_app.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'translations'.
Get.addTranslations(translations!.keys);
^^^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* Where:
Script '/home/auriga/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1201
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/auriga/snap/flutter/common/flutter/bin/flutter'' finished with non-zero exit value 1
* 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 13s
Exception: Gradle task assembleDebug failed with exit code 1
I tried to run my other Flutter projects to check whether it was because of the IDE or if I did something wrong. Surprisingly, I was getting the same error in every project where I used the GetX
package. I was using Vscode, so I tried to run my project in Android Studio and was getting the same error.
After stumbling here and there, I found that the issue was because of the .pub-cache
folder. So the flutter pub cache repair
command solved my issue.
flutter pub cache repair
This command does take some time, as it redownloads every package.