'Error: Member not found: 'packageRoot', how to solve ignore: deprecated_member_use in Flutter?
In my flutter project, I have made some updates of plugins and then used flutter upgrade. After that, whenever I am running my flutter project it is showing following error-
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.2/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'.
io.Platform.packageRoot; // ignore: deprecated_member_use
^^^^^^^^^^^ FAILURE: Build failed with an exception.
* Where: Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102
* What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' 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 20s Exception: Gradle task assembleDebug failed with exit code 1
So, I need a suggestion that how can I solve this issue?
Solution 1:[1]
For me, cleaning and getting the packages didn't work. This error started after I upgraded flutter. I was on the master channel, a quick fix for me was to switch to stable.
flutter channel stable
flutter upgrade
Perhaps theres a better solution which deals with platform package directly.
Solution 2:[2]
You need to upgrade your dependencies to fix this issue, so run:
flutter pub upgrade
If this still doesn't work then it means you are having this issue from transitive dependencies on platform
(platform
with version lower than 3.1.0
has this problem). So, override the platform
package in your pubspec.yaml
file like this:
dependency_overrides:
platform: ^3.1.0
Solution 3:[3]
Try add in pubspec.yaml file
dependencies: // under dependencies:
platform: ^3.1.0
then run flutter pub get
Why this error occurred
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'. io.Platform.packageRoot; // ignore: deprecated_member_use
this is the kind of error that you will get when you build the file.
if you notice the error was caused by package
platform:3.0.0
so we are just overriding this by incrementing it to 3.1.0
Solution 4:[4]
The only thing that could help me was to delete the pubspec.lock
file from the project folder and only then run
flutter clean
flutter pub get
Solution 5:[5]
flutter pub upgrade
flutter clean
flutter pub get
Solution 6:[6]
I had the same issue and I have solved it with the following steps:
- run
flutter pub upgrade
- run
flutter pub outdated
- run
flutter pub clean
Note: run flutter pub clean
in project root and in example packege.
Another important thing make sure you are on the stable version of Flutter.
Solution 7:[7]
firstly, run
flutter pub outdated
then
flutter pub upgrade --major-versions
Solution 8:[8]
I fixed it with one command:
$ flutter pub cache repair
Solution 9:[9]
If all solutions above doesn't work for you just like me,
If the problem occurs immedately you upgrade your flutter
- run
fluter downgrade 2.0.1 //2.0.1 means your working previous version of flutter
- after downgrading, click on the extensions button or use shorcut Ctrl+SHift+X, then uninstall and re-install Flutter and Dart.
this works for me.
Solution 10:[10]
For Flutter iOS Users:
After running following commands:
flutter channel stable
flutter upgrade
flutter pub upgrade
After completing the process, try
pod repo update
pod install
or
pod install --repo-update
Its worked for me. Hope it will be helpful.
Solution 11:[11]
I fixed it : compileSdkVersion 31, and upgrade kotlin-version
Solution 12:[12]
Solution 13:[13]
Solution
A. deleting pubspec.lock
- Delete
pubspec.lock
file - For good measures, update
platform
's parent pub e.g.path_provider
to the latest version. flutter pub get
B. pubspec dependency override
- Add
platform
with its latest version as a dependency override
dependency_overrides:
# fix `packageRoot`compile error for iOS, because `path_provider` is using an old version of `platform`
platform: ^3.1.0 # overrides `path_provider`
flutter pub get
Root Cause
platform
pub is out of date. Most likely in your case it's a transitive dependency frompath_provider
pub.- For some reason,
flutter pub get
won't updateplatform
which is a transitive dependency. Even if you change the version of its parent pubpath_provider
to the latest version and callflutter pub get
again.
Inspecting platform
pub version
A. flutter pub deps
to print package dependency graph. Then find "- platform" string within the output.
B. Inside pubspec.lock
file, look for "platform:" string.
Solution 14:[14]
Enter the following into the terminal at the path of your project.
- flutter pub cache repair
- flutter pub upgrade
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow