question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analysis server sometimes fails to resolve flutter_gen package after running "pub get"

See original GitHub issue

Describe the bug Almost every hour there’s a situation when after getting packages or updating the .arb files the analyzer hangs for a second and then looses information about the Flutter-generated localization files.

This is partially related to #3270 as sometimes this issue occurs after Flutter extension tries to format the file. In this particular case however, it occurred after adding new package.

To Reproduce Steps to reproduce the behavior:

  1. Open project and add new package in pubspec.yaml
    • it may be significant that the package is a local flutter package stored in ./packages/package_name subdirectory
  2. Run Pub: Get packages in command palette
  3. Try to reference the new package somewhere in the widget tree
  4. Notice it doesn’t get imported
  5. Run Pub: Get packages again
  6. Analyzer restarts and after that it looses information about AppLocalizations, running Pub: Get packages doesn’t help and only way out of that is either restarting analyzer or VS Code entirely

I was able to reproduce it in my project just by removing package from pubspec.yaml, calling Pub Get Packages several times, and then adding the package again.

Expected behavior The package should be available immediately after getting packages for the first time. The AppLocalizations should not be lost, as they are still present in the .dart-tool directory.

Screenshots CleanShot 2021-06-29 at 11 23 33@2x

Logs

I sent the Dart instrumentation and analysis logs to logs@dartcode.org

Versions (please complete the following information):

[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale pl-PL)
    • Flutter version 2.2.2 at /Users/dominik/fvm/versions/stable
    • Framework revision d79295af24 (3 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/dominik/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dominik/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.23.0

[✓] Connected device (3 available)
    • SM T500 (mobile) • R9TR105TMWJ • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos       • darwin-x64     • macOS 11.4 20F71 darwin-x64
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 91.0.4472.114

• No issues found!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:16
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

10reactions
felix-htcommented, Nov 29, 2021

A hack that works for me - i pinned .dart_tool/package_config.json in vscode. Whenever the error happens i just save the file and the errors disappear. No need to reload the windows any longer.

Would still be nice if a proper fix would land soon.

8reactions
orestesgaolincommented, Sep 2, 2021

Just wanted to update that after recent update of VS Code extension v3.26.0 and bumping Flutter to 2.5.0-5.2.pre it still happens the same way as before 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Target of URI doesn't exist: 'package:flutter_gen/gen_l10n ...
Next, run pub get packages, then import the flutter_localizations library: import 'package:flutter_localizations/flutter_localizations.dart';.
Read more >
Solving problems when pub get fails | Dart Cookbook
The pub package manager is a complex tool with many functionalities, so it is not surprising that occasionally something goes wrong. The pub...
Read more >
All about the Pub command line tool for Flutter and Dart
When you run flutter pub get , it gets the exact version of the package specified by your pubspec.lock file. To see that...
Read more >
A Guide to Flutter Localization | Phrase
In this article, we'll show you how to use Flutter's native localization package to localize your mobile apps for Android and iOS. We...
Read more >
FlutterGen - Google Dev Library | What will you build?
Get rid of all String-based APIs. ... flutter packages pub run build_runner build. Usage. Run fluttergen after the configuration pubspec.yaml .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found