Flutter force higher package dependency version - flutter

TLDR: How to force a specific Flutter package (library) version for the entire app?
Let's suppose I have the following dependencies in my pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
datetime_picker_formfield: 0.4.3
date_utils: 0.1.0+3
intl: 0.15.8
which gives me a version conflict error:
Because flutter_app depends on date_utils 0.1.0+3
which depends on intl ^0.16.0, intl ^0.16.0 is required.
but when we change intl to intl: 0.15.8 we get:
Because flutter_app depends on datetime_picker_formfield 0.4.3
which depends on intl ^0.15.8, intl ^0.15.8 is required.
How to force intl: 0.16.0 for both: datetime_picker_formfield and date_utils packages?

Use dependency_overrides to force a specific package version for the entire Flutter app.
dependency_overrides:
intl: 0.16.0
So we get:
dependencies:
flutter:
sdk: flutter
datetime_picker_formfield: 0.4.3
date_utils: 0.1.0+3
intl: 0.16.0
cupertino_icons: ^0.1.2
dependency_overrides:
intl: 0.16.0

Related

How to resolve version conflicts between packages?

I'm making a function to record voice and save it as a file. However, an error occurred when pub get to the pubspec.yaml file.
Because every version of flutter_audio_recorder depends on file ^5.0.4 and shared_preferences_windows >=2.0.0 depends on file ^6.0.0, flutter_audio_recorder is incompatible with shared_preferences_windows >=2.0.0.
And because shared_preferences 2.0.9 depends on shared_preferences_windows ^2.0.0 and no versions of shared_preferences match >2.0.9 <3.0.0, flutter_audio_recorder is incompatible with shared_preferences ^2.0.9.
So, because mirinae_gugu depends on both shared_preferences ^2.0.9 and flutter_audio_recorder ^0.5.5, version solving failed.
pub get failed (1; So, because mirinae_gugu depends on both shared_preferences ^2.0.9 and flutter_audio_recorder ^0.5.5, version solving failed.)
The package I am using is below.
cupertino_icons: ^1.0.2
provider: ^6.0.0
carousel_slider: ^4.0.0
rxdart: ^0.27.2
font_awesome_flutter: ^9.1.0
shared_preferences: ^2.0.9
flutter_signin_button: ^2.0.0
image_picker: ^0.7.0
path_provider: ^2.0.2
sizer: ^2.0.15
get: 3.24.0
flutter_svg: ^0.19.1
intl: ^0.17.0
cached_network_image: ^3.1.0
camera: ^0.9.2
google_speech: ^2.0.1
sound_stream: ^0.3.0
flutter_animation_progress_bar: ^2.0.1
noise_meter: ^3.0.2
rflutter_alert: ^2.0.2
audioplayers: ^0.19.1
fluttertoast: ^8.0.7
share: ^2.0.4
permission_handler: ^8.1.4+1
flutter_audio_recorder: ^0.5.5
Even though I fixed the error between flutter_audio_recorder and shared_preferences, I still get the error between different packages.
How can I solve this?
Run flutter clean. Then
In pubspec.yaml give
audioplayers: any
Delete pubspec.lock. Then run flutter pub get and flutter run. It should work as expected
Use flutter_audio_recorder2 instead. This is an exact clone of flutter_audio_recorder but it supports dart null-safety support.
flutter_audio_recorder2: ^0.0.2
Not Recommended Solution (using old flutter_audio_recorder package).
Below is the solution using flutter_audio_recorder. This is the opened pull request #58 - Added sound null safety support. So you can use it like below
Change the flutter_audio_recorder dependencies like below
flutter_audio_recorder:
git:
url: git://github.com/fayeed/flutter_audio_recorder.git
ref: sound-null-safety
Use dependency override, suppose some_package and another_package depends on incompatible url_launcher version, you can resolve conflict this way:
dependencies:
some_package:
another_package:
dependency_overrides:
url_launcher: '5.4.0'

Flutter path_provider and connectivity_plus version solving failed

I can't install Flutter's connectivity package due to a version conflicting issue with the path_provider package. I tried exchanging different versions of both packages but no luck. Can anyone please guide me on how to fix this issue here?
Error on Log :
Because connectivity_plus >=1.0.2 depends on connectivity_plus_platform_interface ^1.0.2 which depends on plugin_platform_interface ^2.0.0, connectivity_plus >=1.0.2 requires plugin_platform_interface ^2.0.0.
And because path_provider >=1.6.4 <2.0.0-nullsafety depends on path_provider_platform_interface ^1.0.1 which depends on plugin_platform_interface ^1.0.1, connectivity_plus >=1.0.2 is incompatible with path_provider >=1.6.4 <2.0.0-nullsafety.
So, because cliffjumper depends on both path_provider ^1.6.11 and connectivity_plus ^1.0.5, version solving failed.
pub get failed (1; So, because cliffjumper depends on both path_provider ^1.6.11 and connectivity_plus ^1.0.5, version solving failed.)
In pubspec.yaml file :
enter code version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
rxdart: ^0.26.0
sqflite: ^1.3.1
path_provider: ^1.6.11
http: ^0.12.1
#flutter_facebook_login: ^3.0.0
#google_sign_in: ^4.5.1
flutter_blue: ^0.8.0
google_maps_flutter: ^2.0.5
geolocator: ^6.1.6
device_info: ^2.0.0
shared_preferences: ^0.5.10
crypto: ^3.0.1
uuid: ^3.0.4
latlong: ^0.6.1
geocoder: ^0.2.1
us_states: ^1.0.3
package_info: ^0.4.3+2
weather: ^1.2.4
connectivity_plus: ^1.0.5
try to update all the plugins to their latest version or simply use 'any' keyword instead of version code

Error in setting up flutter_localizations package

I need to add flutter_localizations package to use Arabic language in my application, but when I add it in pubspec.yaml, it gives me the following error:
Because calendar_timeline >=0.6.1 depends on intl ^0.16.1 and every version of flutter_localizations from sdk depends on intl 0.17.0-nullsafety.2, calendar_timeline >=0.6.1 is incompatible with flutter_localizations from sdk.
So, because elderly_app depends on both flutter_localizations any from sdk and calendar_timeline ^0.7.0, version solving failed.
pub get failed (1; So, because elderly_app depends on both flutter_localizations any from sdk and calendar_timeline ^0.7.0, version solving failed.)
This is my pubspec.yaml:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.1
calendar_timeline: ^0.7.0
flutter_datetime_picker: ^1.5.0
date_picker_timeline: ^1.2.1
hijri: ^2.0.3
flutter_week_view: ^1.0.0+2
url_launcher: ^5.7.10
It works when I delete the lines under flutter_localizations like cupertino_icons and calendar_timeline
According to the above message you should decrease your calendar_timeline version to lower than 0.6.1. for example calendar_timeline: 0.6.0
and add this line to pubspec.yaml file:
dependency_overrides:
intl: ^0.16.0
Try updating all of your packages to the latest version.

pub get failed:version solving failed

Flutter_test depends on meta 1.1.8 and firebase_login depends on meta ^1.2.2.
firebase_login depends on flutter_test any from sdk, version solving failed.
pub get failed
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
firebase_auth: ^0.18.0+1
equatable: ^1.2.4
google_sign_in: ^4.5.3
meta: ^1.2.2
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
lint: any
You can get both by
dependencies:
meta: ^1.2.2
dependency_overrides:
meta: ^1.1.8
I have same problem with bloc:
Because every version of passcode_navigator from git depends on flutter_bloc ^7.3.3 and every version of feature_menu from path depends on flutter_bloc ^8.0.0, passcode_navigator from git is incompatible with feature_menu from path
I resolve it with adding to pubspec:
dependency_overrides:
flutter_bloc: any
Do this,
meta: ^1.1.8
And then, run this,
flutter pub get
hi there try to downgrade the version of meta to 1.1.8 i tried and it worked with me in flutter 1.20.1
I experienced a similar issue with Firebase auth and permission_handler:
# pubspec.yaml:
dependencies:
flutter:
sdk: flutter
firebase_auth: ^1.4.1
permission_handler: ^5.1.0+2
The error message (truncated):
Because permission_handler ^5.1.0 depends on permission_handler_platform_interface ^2.0.2 which depends on plugin_platform_interface ^1.0.2, permission_handler ^5.1.0 requires plugin_platform_interface ^1.0.2.
And because firebase_auth 1.4.1 depends on firebase_core_platform_interface ^4.0.1 and no versions of firebase_auth match >1.4.1 <2.0.0, permission_handler ^5.1.0 is incompatible with firebase_auth ^1.4.1.
So, because my_flutter_project depends on both firebase_auth ^1.4.1 and permission_handler ^5.1.0+2, version solving failed.
A solution that worked for me:
Update permission_handler to the latest version:
flutter pub add permission_handler
Update meta to 1.2.2
meta: ^1.2.2
also update flutter using flutter upgrade command
flutter upgrade

Flutter image version issue

I have just upgraded my flutter version and now I am facing the following issue when I get the packages in pubsec.yml file:
Because every version of flutter_test from sdk depends on image 2.1.4 and Instant_Feedback depends on image ^2.1.9, flutter_test from sdk is forbidden.
So, because Instant_Feedback depends on flutter_test any from sdk,
version solving failed. pub get failed (1; So, because
Instant_Feedback depends on flutter_test any from sdk, version solving
failed.)
My pubsec.yml file
dependencies:
flutter:
sdk: flutter
http: ^0.12.0+2
shared_preferences: ^0.5.4+8
firebase_messaging: ^6.0.3
flutter_crashlytics: ^1.0.0
firebase_core: ^0.4.2+1
cupertino_icons: ^0.1.3
device_calendar: ^1.0.0+2
cloud_firestore: ^0.12.11
auto_size_text: ^2.1.0
flutter_expandable_menu: ^0.0.1
webview_flutter: ^0.3.17
flutter_spinkit: ^4.1.1+1
get_it: 2.1.0
bloc: ^0.15.0
flutter_bloc: 0.21.0
equatable: 0.5.1
rflutter_alert: ^1.0.3
expandable: ^3.0.1
connectivity: ^0.4.6
firebase_auth: ^0.15.1
flutter_email_sender: ^2.2.1
mockito: 4.1.1
flutter_secure_storage: ^3.3.1+1
image_picker: ^0.6.2+2
async: any
image: ^2.1.10
image_crop: ^0.3.1
flutter_cache_manager: ^1.1.3
circular_profile_avatar: ^1.0.3
package_info: ^0.4.0+12
flutter_local_notifications: ^0.8.4+3
flutter_webview_plugin: ^0.3.10
url_launcher: ^5.2.7
flutter_localizations:
sdk: flutter
flutter_cupertino_localizations: ^1.0.1
dev_dependencies:
flutter_driver:
sdk: flutter
test: any
ozzie: 2.0.1
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- lib/app/assets/images/
- lib/app/assets/flags/
- lang/en.json
- lang/de.json
Because every version of flutter_test from sdk depends on image 2.1.4 and Instant_Feedback depends on image ^2.1.9, flutter_test from sdk is forbidden.
I faced the same issue. Couldn't find the specific reason for the flutter_test depending on a specific version of this image library. Maybe it's an issue from the flutter side. So here are some workaround solutions:
comment out the flutter_test dev_dependency.
dev_dependencies:
# flutter_test:
# sdk: flutter
set the required version.
Instead of 2.1.12, I set the Image package version to 2.1.4 (as requested in the error message)
image: ^2.1.4
If more than one packages versions are noncompatible to each other, and you don't know their exact compatible version, you can find it by setting both the conflicting dependencies to any, e.g.
flutter_crashlytics: any
firebase_core: any
This will automatically figure out the compatible package version. Check these new compatible versions in pubspec.lock file, which will be auto-generated by running flutter package get.
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
flutter_crashlytics:
...
version: "1.0.0"
firebase_core:
...
version: "0.4.2+1"
Replace any with those correct versions.
flutter_crashlytics: 1.0.0
firebase_core: 0.4.2+1
Note: You should never leave your versions as any