I’ve been encountering the lint warning message in a project that imports a package that is responsible for maintaining dependencies:
"The imported package ‘get’ isn’t a dependency of the importing package."
The reason for this is that I didn’t add the package directly on my project pubspec.yaml because I’ve created a package that receives all my dependencies so I can centralize changes on all the projects that depends on it.
The way I import the dependencies package for now is using path, as show in the examples.
Dependencies package pubspec.yaml example:
name: dependencies
description: dependencies of projects
version: 0.0.1
publish_to: 'none'
environment:
sdk: '>=3.0.5 <4.0.0'
dependencies:
flutter:
sdk: flutter
get: ^4.6.5
logger: ^1.1.0
device_info: ^2.0.0
get_it: ^7.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
Main Project pubspec.yaml example:
name: main_project
description: main_project that depends on the package
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: '>=3.0.5 <4.0.0'
dependencies:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
dependency_overrides:
dependencies:
path: packages/common/dependencies
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
I would like to know if there is any way that I can fix this lint warning message or should I just deactivate this message.
I’ve seen this answer but I don’t know if using get: any will try to search the latest version on pub.dev or it will recognize that I’m importing it from my depencies package manager.
>Solution :
Inside your dependency manager package you should have a file in lib with the same name that your package lib/dependencies.dart, there you should export all your transitive dependencies that you want to expose and add an ignore message lint:
// ignore: invalid_export_of_internal_element
export 'package:get/get.dart';
.... //Same with all the packages you want to expose from this library