how can I use flutter_test from sdk and the package test? what version of test uses test_api 0.4.3? - flutter

I am trying to run some basic unit test for my flutter app. But when I run pub get I get the following error after including test: 1.20.0 in my pubspec:
dev_dependencies:
dependency_validator: ^3.1.0 # run flutter pub run dependency_validator
#integration_test:
# sdk: flutter
flutter_test:
sdk: flutter
test: ^1.20.0
so when I run f pub get I see:
Because test >=1.20.0 depends on test_api 0.4.9 and every version of flutter_test from sdk depends on test_api 0.4.3, test >=1.20.0 is incompatible with flutter_test from sdk.
So, because myapp depends on both flutter_test from sdk and test ^1.20.0, version solving failed.
pub get failed (1; So, because myapp depends on both flutter_test from sdk and test ^1.20.0, version solving failed.)```
What version of test uses test_api 0.4.3?

Try overriding test_api to 0.4.9 in your pubspec.yaml file:
dependency_overrides:
test_api: 0.4.9
or
dependency_overrides:
analyzer: ^3.0.0
You can probably remove this next time flutter updates.

I can just use import 'package:flutter_test/flutter_test.dart'; instead of importing directly from the test package in my test file. So I don't need to include test: 1.20.0 in my pubspec.

Add test_api in dependency_overrides
example:
dependency_overrides:
test_api: ^0.4.17
dev_dependencies:
flutter_test:
sdk: flutter
bloc_test: ^9.1.0
build_runner: ^2.3.3

Related

flutter packages get command gives an error error

hello I tried running flutter pub get and I was faced with this error:
flutter pub get
Waiting for another flutter command to release the startup lock...
Running "flutter pub get" in Deutsche-Flutter...
Because every version of flutter_test from sdk depends on test_api 0.3.0 and mockito 4.1.4 depends on test_api ^0.2.19-nullsafety, flutter_test from sdk is incompatible with mockito 4.1.4.
And because no versions of mockito match >4.1.4 <5.0.0, flutter_test from sdk is incompatible with mockito ^4.1.4.
So, because deutsche depends on both mockito ^4.1.4 and flutter_test any from sdk, version solving failed.
pub get failed (1; So, because deutsche depends on both mockito ^4.1.4 and flutter_test any from sdk, version solving failed.)
exit code 1
I already ran flutter upgrade and tried to run flutter pub get here are my dependencies:
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: ^1.0.0
flutter_svg: ^0.19.1
flutter_bloc: ^6.1.2
get: ^3.23.1
rxdart: ^0.19.0
http: ^0.12.2
google_fonts: ^0.3.9
circular_countdown_timer: ^0.1.0
pin_code_fields: ^2.4.0
google_nav_bar: ^3.2.0
line_icons: ^0.2.0
shared_preferences: ^0.5.12+4
flutter_launcher_icons: ^0.7.2+1
rive: ^0.6.8
timer_count_down: ^1.0.4+1
logger: ^0.9.4
dartz: ^0.9.0-dev.6
freezed_annotation: ^0.12.0
bloc_test: ^7.1.0
mockito: ^4.1.4
jwt_decode: ^0.3.1
carousel_slider: ^3.0.0
dev_dependencies:
build_runner:
freezed: ^0.12.7
flutter_test:
sdk: flutter
Update all of your plugins and that will work. And do make sure that all of them are null-safety enabled.
try replacing mokito version as any as follows.
mockito: any
then check the pubspeck.lock file and search mokito and take that version number from there and replace it in pubspec.yaml file
update the mockito package to => mockito: ^5.2.0

Flutter integration_test package conflict with my code and cannot be resolved by tweaking package versions - so the whole app cannot run

I have an app (with null-safety), and want to use integration_test package to do some testing. The pubspec.yaml looks like:
dependencies:
archive: ^3.1.2
...
dev_dependencies:
build_resolvers: ^2.0.0
build_runner: ^1.11.5
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
...
Then it errors:
Because every version of flutter_driver from sdk depends on archive 2.0.13 and my_app depends on archive ^3.1.2, flutter_driver from sdk is forbidden.
I cannot use the non-null-safety version (2.x) of archive package, because if I do so, my app code will fail to run in null safety mode! I can accept that my tests run in non-null-safety mode, but I cannot tolerate my app code run in non-null-safety mode.
Thanks for any suggestions!
You need to override the archive package version to tell flutter_driver to use the latest one:
dev_dependencies:
build_resolvers: ^2.0.0
build_runner: ^1.11.5
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
dependency_overrides:
archive: ">=3.1.2"

Every version of integration_test depends on flutter_driver any from sdk which depends on crypto 2.1.5

I've been getting an error ever since I tried adding integration_test package along with get_test and it's primarily due to the fact that just_audio depends on crypto: ^3.0.0 while integration_test depends on crypto: ^2.1.5.
I tried to look online to see if it's possible to only install dependencies without dev_dependencies however it seems like flutter pub cli tool doesn't support that yet based on this issue.
Here is my pubspec.yaml
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
share: ^2.0.1
get:
get_storage:
shared_preferences: ^2.0.5
audio_service: 0.17.0-nullsafety.0
just_audio: ^0.7.4
dev_dependencies:
flutter_test:
sdk: flutter
get_test: ^3.13.3
integration_test: ^1.0.2+1
test: ^1.14.4
This is the error I am getting.
Because every version of integration_test depends on flutter_driver any from sdk which depends on crypto 2.1.5, every version of integration_test requires crypto 2.1.5.
And because just_audio 0.7.4 depends on crypto ^3.0.0 and no versions of just_audio match >0.7.4 <0.8.0, integration_test is incompatible with just_audio ^0.7.4.
So, because egy_fm_radio depends on both just_audio ^0.7.4 and integration_test ^1.0.2+1, version solving failed.
pub get failed (1; So, because egy_fm_radio depends on both just_audio ^0.7.4 and integration_test ^1.0.2+1, version solving failed.)
I think this specific issue could have been be resolved by updating the Flutter SDK to the latest (>=2.2.0), but if there's anybody experiencing a similar issue, consider using Dependency overrides to override dependencies of built-in packages such as integration_test and flutter_driver.
dependency_overrides:
crypto: ^3.0.0
Note that this involves some risk and pub will show you a warning during dependency resolution.
Looking through your pubspec.yaml it appears the problem lies within the crypto dependency mismatch.
Inside your pubspec.yaml you can explictly declare the latest crypto version:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
share: ^2.0.1
crypto: 3.0.1
get:
get_storage:
shared_preferences: ^2.0.5
audio_service: 0.17.0-nullsafety.0
just_audio: ^0.7.4
dev_dependencies:
flutter_test:
sdk: flutter
get_test: ^3.13.3
integration_test: ^1.0.2+1
test: ^1.14.4
What happens is that when you use so many packages, some of those packages use some other packages. It may so happen that two or more packages use the same package.So, it creates an error incase of mismatch because you cannot have two different versions of the same package.

Flutter theme version solving failed

I am trying to run a flutter theme code in visual studio code and facing this issue after running command (flutter run)
Because every version of flutter_test from sdk depends on vector_math 2.1.0-nullsafety.5 and fstore depends on vector_math 2.0.8, flutter_test from sdk is forbidden.
So, because fstore depends on flutter_test any from sdk, version solving failed.
Running "flutter pub get" in ecomputex...
pub get failed (1; So, because fstore depends on flutter_test any from sdk, version solving failed.)
Please helpenter image description here
just add this line of code in your pubspec
dependency_overrides:
vector_math: 2.1.0-nullsafety.5
this will override the dependency, and you can use whatever version you want. you might need to change it the version of the package.
my code example:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
file_picker: ^3.0.0
hive: ^2.0.0
hive_flutter: ^1.0.0
dependency_overrides:
path_provider: 2.0.1

Diagnosing Flutter version solving issue

While following the instructions to add integration tests to my Flutter app, I get the following error running packages get:
Because test <1.3.0 requires SDK version >=1.8.0 <2.0.0-∞ and test >=1.3.0 <1.6.1 depends on stream_channel ^1.6.0, test <1.6.1 requires stream_channel ^1.6.0.
And because test >=1.6.0 <1.6.5 depends on analyzer >=0.26.4 <0.37.0 and test >=1.6.4 <1.6.8 depends on test_api 0.2.6, test <1.6.8 requires stream_channel ^1.6.0 or analyzer >=0.26.4 <0.37.0 or test_api 0.2.6.
And because test >=1.6.8 <1.6.11 depends on test_api 0.2.7 and test >=1.6.11 depends on test_api 0.2.8, every version of test requires test_api 0.2.6 or 0.2.7 or 0.2.8 or stream_channel ^1.6.0 or analyzer >=0.26.4 <0.37.0.
And because every version of flutter_test from sdk depends on both stream_channel 2.0.0 and test_api 0.2.5, if flutter_test any from sdk and test any then analyzer >=0.26.4 <0.37.0.
And because json_serializable 3.2.3 depends on analyzer >=0.37.1 <0.39.0 and my_app depends on test any, flutter_test from sdk is incompatible with json_serializable 3.2.3.
So, because my_app depends on both json_serializable 3.2.3 and flutter_test any from sdk, version solving failed.
That presumably indicates some sort of version conflict through the dependency graph, but I'm at a bit of a loss to work out quite what exactly the issue is or what I could do about it. My pubspec.yaml looks like:
environment:
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
flutter_svg: 0.14.2
email_validator: 1.0.0
dio: 3.0.2
dio_cookie_manager: 1.0.0
cookie_jar: 1.0.1
provider: 3.1.0
path_provider: 1.3.0
json_annotation: 3.0.0
timeago: 2.0.19
flutter_launcher_icons: 0.7.3
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: 1.7.1
json_serializable: 3.2.3
mockito: 4.1.1
flutter_driver:
sdk: flutter
test: any
Hoping someone can give me a pointer in the right direction.
did you try to remove the test dependency from the pubsec.yaml?
Looks like that the flutter_test package is already present on the flutter SDK.