Flutter packages path not found

Viewed 850

I've installed Flutter without Android Studio following these two tutorials: https://medium.com/@quicky316/install-flutter-sdk-on-windows-without-android-studio-102fdf567ce4 and https://dev.to/ejgamer21/install-flutter-without-android-studio-58bi. I have connected my phone with USB debugging enabled and I've run flutter doctor: everything seems to be fine (although I haven't configured an IDE yet). Then I've tried to run the "Hello world" example that comes with Flutter using flutter run in the hello_world directory, but I get this error:

lib/main.dart:5:8: Error: Error when reading '/C:/b/s/w/ir/k/archive/flutter/packages/flutter/lib/widgets.dart': Impossibile trovare il percorso specificato.
import 'package:flutter/widgets.dart';
       ^
lib/main.dart:12:16: Error: Method not found: 'Key'.
          key: Key('title'),
               ^^^
lib/main.dart:13:26: Error: Getter not found: 'TextDirection'.
          textDirection: TextDirection.ltr
                         ^^^^^^^^^^^^^
lib/main.dart:11:9: Error: Method not found: 'Text'.
        Text('Hello, world!',
        ^^^^
lib/main.dart:9:11: Error: Method not found: 'Center'.
    const Center(
          ^^^^^^
lib/main.dart:8:3: Error: Method not found: 'runApp'.
  runApp(
  ^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\mpepi\Android\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\mpepi\Android\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                         4,7s
Exception: Gradle task assembleDebug failed with exit code 1

("Impossibile trovare il percorso specificato" means "Couldn't find the specified path") Something seems to be wrong with the path for the packages, I have located the required file at C:\Users\mpepi\Android\flutter\packages\flutter\lib which of course is different from the one in the first line. I have set all environment variables as the tutorials explain, what am I missing?

3 Answers

Delete in the .vscode file. Restart the flutter application of visual studio code and run 'Flutter run'. It worked for me.

You could try to set "File Transfer" mode on your phone, it usually is on the notification bar if the phone is conected

For some cases I've also faced the similar issue. This problem is likely to arise when flutter doesn't get the packages. It wasn't even getting the material package, like your widget package.

Fix: Go to pubspec.yaml file. Make sure your internet connection is on and working. If you're developing in vscode you'll find buttons at top-right corner. Click Get Packages and wait until flutter downloads the packages.

If you don't find those buttons, then from the command line navigate to the project folder and run flutter pub get or flutter packages get.

Related