import 'package:using_tabs/tabs/first.dart'; >> Target of URI doesn't exist

509

You can use the package-style imports for all files under your project's lib/ directory. The path is simply the relative path from lib/ (The lib/ directory itself is omitted) to the file. After adding a new package-style import you may need to run flutter packages get, or your IDE may handle this automatically.

In a pubspec.yaml give your project a name.

name: my_project

And with a directory structure like the following

 pubspec.yaml
 lib/
 ├── main.dart
 ├── fizz.dart
 ├── foo/
 │   ├── bar.dart
 │   ├── foo.dart

Then inside of main.dart you can import using the package: style like the following:

import 'package:my_project/fizz.dart';
import 'package:my_project/foo/bar.dart';

Lastly, if you use and IDE like Intellij, Android Studio, or Visual Studio Code you can use the auto import feature by using an identifier from an unimported library and then using the contextual action to add an import. This action will add a package-style import to your current library.

Share:
509
naim5am
Author by

naim5am

Updated on December 05, 2022

Comments

  • naim5am
    naim5am over 1 year

    import 'package:using_tabs/tabs/first.dart';

    This is from an example code here >> https://github.com/nisrulz/flutter-examples/blob/master/using_tabs/lib/main.dart

    noob question. If I try to reuse the code and replace using_tabs with my project name, and create a file first.dart in a folder tabs the IDE is throwing an error, Target of URI doesn't exist

    I know I could fix it by changing it to something like

    import './ThirdTab.dart' as third_tab;
    

    But I'm interested in understanding the package syntax. Documentation didn't help much.

  • naim5am
    naim5am almost 6 years
    Thanks, going by your example, I had foo* under the main project directory, instead of in **lib