How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - Printable Version +- 0Day Forums (https://zeroday.vip) +-- Forum: Coding (https://zeroday.vip/Forum-Coding) +--- Forum: Flutter & Dart (https://zeroday.vip/Forum-Flutter-Dart) +--- Thread: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart (/Thread-How-to-avoid-lint-problem-quot-Depend-on-referenced-packages-quot-for-gen-l10n-app-localizations-dart) |
How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - aliethmoid891561 - 07-21-2023 On my Flutter app, I've got this problem with lint rule : [depend_on_referenced_packages][1] [![enter image description here][2]][2] This file is generated here [![enter image description here][3]][3] Do you have any idea how to solve this without passing by ignore 'depend_on_referenced_packages' ? in my pubspec.yaml, I only have this : [![enter image description here][4]][4] Thanks a lot [1]: [To see links please register here] [2]:[3]: [4]: RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - Mruncommunicating922 - 07-21-2023 Based on the [documentation]( [To see links please register here] ), it seems that just having a dependency on `flutter_localizations` only is not enough. Your dependencies should look like this:``` dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter intl: ^0.17.0 # Add this line ``` RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - hoplomachos3631 - 07-21-2023 I don't know how to ignore only generated packages, but this is how you turn off the rule entirely: 1. Create a file `analysis_options.yaml` in your project root. 2. Paste this: ``` include: package:flutter_lints/flutter.yaml linter: rules: depend_on_referenced_packages: false ``` Additional information about this file can be found at [To see links please register here] RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - supervisionarylxoiahz - 07-21-2023 I'm using `collection.dart` more than a dozen places in my app and recently after the Flutter 3.0 upgrade this lint started to pop up for me. I think `depend_on_referenced_packages` is a really useful lint to warn you about unnecessary imports. I would never turn it off entirely for the project (@EzPizza's answer). You can suppress the lint for an affected file by adding this comment to the file: `// ignore_for_file: depend_on_referenced_packages` But it's even better to fix the root cause of the problem and include the indicated dependencies into your `pubspec.yaml`. Like for example what @mkobuolys proposes. RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - acrefoot840 - 07-21-2023 for me it was because the packages i was having this warning on didn't support flutter 3 yet. RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - heparinized78892 - 07-21-2023 this is [the official link][1] [1]: [To see links please register here] you should direct dependency not indirectly dependency. RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - josineusez - 07-21-2023 I'm only posting this because the other answers either didn't help me or I didn't understand them. I got the same warning on a different package, namely page_transition. Here's what I found on why the problem occurs: > When importing a package, add a dependency on it to your pubspec. > > Depending explicitly on packages that you reference **ensures they will always exist and allows you to put a dependency constraint on them to guard you against breaking changes.** Meaning you are right to look for a solution other than to ignore it. Here's how I fixed it: I went to pubspec.yaml and added the following under dependencies: dependencies: page_transition: ^2.0.9 You can add the dependency for your package which you would have to look up. I just googled "flutter app_localizations" and this came up, you can see the latest version under the **Installing** tab. [localization 2.1.0][1] So, if you're using that package, as an example, you would have to add dependencies: localization: ^2.1.0 [1]: [To see links please register here] RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - palatineuw - 07-21-2023 Just add the package explicitly. 1. run `flutter pub add flutter_gen` 2. run `flutter pub get` For more info, see [To see links please register here] RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - unhousewifely878949 - 07-21-2023 For me, this error occurs because I accidentally put my package name in the dev_dependencies section. Putting my package name in dependencies section fixed my problem. RE: How to avoid lint problem "Depend on referenced packages" for gen_l10n/app_localizations.dart - lyonnesse1 - 07-21-2023 For me, I **accidentally** put the package `url_launcher: ^6.1.7` under `dev_dependencies:` **Solution:** I **removed** the package from `dev_dependencies` and **added** it below `dependencies:` |