shared preferences not working in the background in flutter - flutter

i am using shared_preferences: ^2.0.7 with flutter_background_service: ^0.1.5 in flutter
but when call shared preferences give me the error
"Flutter: Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)"
When working in the forground mode, the call is done correctly, this problem occurs only about the call in the background mode.

usually this happens when thirdparty pulgin files are not properly included in build apk , to avoid this try :
flutter clean
flutter pub get
flutter run
this will make sure proper build with required files.
Tip : when adding a new plugin to pubspec.yaml file avoid Hot reload and Hot restart make sure to build apk from scratch so that all required files included in your build.

Related

MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) in flutter

Both IOS and Android build was working fine. But recently when I tried to run my app in IOS device I got this error and the screen keeps loading in splash screen.
I tried multiple ways like,
flutter clean
flutter pub get
deleting pubspec.lock file
deleting podfile.lock file
nothing solved my issue.
But when I tried this method,
SharedPreferences.setMockInitialValues({});
The app will run in ios, but when we kill the app and open it again all the values stored in shared preferences will be null.
You can try these steps:
flutter clean
flutter pub get
Invalid Caches and Restart

I am having a problem building a Flutter App

I has a build a flutter app before successfully, but I try to update the code of my flutter app because I discovered some bugs but when j try to build it I get a error about error configuring video_player Android, I try to add it as a Dependencies but still it didn't work, I also invalidate cache's too it didn't work because it also said something about Cache's, I also upgraded my flutter SDK, still it didn't work, I will attach a image under this write up.
The error I am facing 😭😪
The error I am facing 😭😪
Write below command in terminal to clear cache with android project path.
flutter pub cache clean
./gradlew clean
gradlew cleanBuildCache

Image picker flutter issue

when I try to use image_picker and run the flutter project it gives me error
A problem occurred configuring project ':image_picker_android'.
Could not load compiled classes for build file 'C:\Users\ZerpSteve\Documents\flutter_windows_2.10.2-stable\flutter.pub-cache\hosted\pub.dartlang.org\image_picker_android-0.8.5\android\build.gradle' from cache.
Use this command in your flutter project folder and rerun your project.
flutter clean && flutter pub get

Undefined name 'AppLocalizations'. (Documentation) after creating a new project

I created a new Flutter project and did a
flutter pub get
There are no errors from the framework except the one from AppLocalizations class.
Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.
Another error (obviously because of the same package)
NOTE:
I have already tried:
Restarting IDE + Invalidate Caches and Restart
flutter pub add flutter_gen
Restarting Dart Analysis Server
Updating packages
I'm using: Flutter 2.6.0-11.0.pre • channel dev
You can expect all sorts of surprises when switching between channels (and specifically when using Dev or Master channel).
If switching to stable or beta channel (flutter channel stable and flutter upgrade) due to some reasons is not an option I'd suggest upgrading flutter (newer version might have a fix) cleaning the proj OR recreatign platform projects:
flutter upgrade
flutter clean
flutter create .
Besides, I'd stick to beta channel rather than dev/master - it's typically better tested and has fewer issues.
Note that in 2022 dev channel is no longer available leaving master as the most recent and least tested branch.
flutter_gen/gen_l10n dir is auto generated by flutter and located in .dart_tool. (It's not related to the package named flutter_gen in pub.dev).
Try this,
flutter clean
then,
flutter pub get
If the flutter_gen/gen_l10n dir is not available yet follow the below steps.
Step 0: Make sure you have these in pubspec.yaml,
flutter:
generate: true
and
dependencies:
flutter_localizations:
sdk: flutter
Step 1: Comment everything related to AppLocalization if you can't run the app with them. (Imports & Usage)
Step 2: Now run the app.
Now the flutter_gen/gen_l10n folder will be generated.
Finally: Un-comment everything related to AppLocalization.
Every time you make changes to .arb files you will need to flutter get / run / hot reload / hot restart the app to update generated localization files.
Change these lines in pubspec.yaml file
From
flutter:
uses-material-design: true
To
flutter:
uses-material-design: true
# Enable generation of localized Strings from arb files.
generate: true
Then run:
flutter clean
flutter pub get
flutter run

The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'

Recently I've updated to flutter 2.5 and the newest androids studio, and tried to compile my flutter project to android device. Android studio throws me the error below. If I write flutter run in a terminal there is no problem compiling to android device.
Guess this must be related to android studio. I tried downgrade to an earlier android studio version, but the problem persists.
I'm not sure what plugin this is, it doesn't seem like any I use in my project.
Edit: If I downgrade flutter from 2.5 to 2.0 my project compiles again. So the problem is within flutter 2.5
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
../plugins/flutter/.pub-cache/hosted/pub.dartlang.org/photo_view-0.11.1/lib/src/core/photo_view_gesture_detector.dart:106:29: Error: The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'.
- 'PointerEvent' is from 'package:flutter/src/gestures/events.dart' ('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
- 'PointerDownEvent' is from 'package:flutter/src/gestures/events.dart' ('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
super.addAllowedPointer(event);
There was an API change in version 2.5 of flutter and several packages must update accordingly.
Your logs show that the exact package which contains the error is photo_view.
Luckily enough the package has just been updated to fix this, so just update its version in your pubspec.yaml:
photo_view: ^0.12.0
UPDATE
If you don't have the package directly in your pubspec
You have two options
1 It's probably a transient dependency, you can run flutter pub deps
to list the installed packages and its dependencies and try to update the one that uses photo_view (if it does have an update)
2 Add a dependency override to your pubspec.yaml, this will effectively override the version of the package being used
dependency_overrides:
photo_view: ^0.12.0
Add this just before your dev_dependencies
from your debug code
('../plugins/flutter/packages/flutter/lib/src/gestures/events.dart').
you open the file or click if there are link clickable
Search for this:
void addAllowedPointer(PointerEvent event) {
and replace with this:
void addAllowedPointer(PointerDownEvent event) {
Here is the reference link
https://flutter.dev/docs/release/breaking-changes/gesture-recognizer-add-allowed-pointer
This problem arises due to the GestureRecognizer Cleanup -
Here is the documentation if you are intrested in the migration code
But in case you just want to build your flutter app without any migrations following are couple of solutions to that problem
You can update photo_view dependency in your pubspec.yaml file to
photo_view :^0.12.0
If you do not want to update your dependency due to any reason you can opt for this temporary fix . In the pubspec.yaml file add the following custom photo_view with better gesture recognition in dependency_overrides.
dependency_overrides:
photo_view:
git: git://github.com/robertodoering/photo_view.git