Sdk: Generates relative instead of package path when importing files under project's lib/ directory

Created on 27 Mar 2018  路  13Comments  路  Source: dart-lang/sdk

_From @tamcy on March 27, 2018 14:10_

When using code completion to generate codes of missing file import, the plugin always generates a package: style import, even when importing from within our own package. But this can break things as "main.dart" is imported relatively, not as a package. It'd be better if relative path syntax is used.

_Copied from original issue: flutter/flutter-intellij#2015_

P2 analyzer-completion area-analyzer type-enhancement

Most helpful comment

Is this still ongoing?
I would love to import packages directly as a relative path instead of package:

All 13 comments

_From @zoechi on March 27, 2018 14:23_

I think the conclusion to this problem was that lib/main.dart should always only contain package imports, then Dart is able to canonicalize libraries properly no matter what form the imports are in other libraries.

_From @stevemessick on March 27, 2018 16:39_

@pq could you take a look and help decide who's best to follow up with this?

I think the general rule is that if you use relative imports, all your imports should be relative, otherwise all should be absolute. Problems arise when there's a mix. In practice, I think @zoechi's advice is spot on. FWIW, if you want the linter to keep you on the rails, you might consider enabling avoid_relative_lib_imports...

cc @bwilkerson, in case he wants to chime in.

(Since this is a general completion issue, moved to the SDK tracker 馃憤 )

When develop in Flutter, the following code won't work if package imports are used.
https://gist.github.com/tamcy/0c4d6cc58f61b6de2740ede56880e8b4

@tamcy that's probably because of import 'main.dart';
Try to avoid importing the entrypoint fie.

@scheglov: is there anything to track here or should I close the issue?

We still might get to this issue, there was same request in VS Code tracker recently.

I would also like to see some linter where I could set relative or absolute path option for my package.

@tenhobi probably best to create an issue in https://github.com/dart-lang/linter

Is this still ongoing?
I would love to import packages directly as a relative path instead of package:

I would like to have both package and relative path suggestions.
How is the progress of this issue?

It would be nice to be able to import both package and relative path.
How is it going?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  3Comments

rinick picture rinick  路  3Comments

DartBot picture DartBot  路  3Comments

brooth picture brooth  路  3Comments

DartBot picture DartBot  路  3Comments