I'm little bit confused about which style of import should I use when importing implementation libraries (code under src/lib
) from another libraries (and tests) in my own package?
The docs recommends the opposite options.
In pub
docs, it says:
When you use libraries from within your own package, even code in src, you can (and should) still use
package:
to import them.
But in "Effective Dart", it says:
When referencing a library inside your package’s lib directory from another library in that same package, use a relative URI, not an explicit
package:
URI.
In the end, which style should I use in such cases:
- import implementation library (under
lib/src/
) from with public library (under justlib/
)? - import implementation library (
lib/src/foo.dart
) from within its test (test/src(?)/foo_test.dart
)? - import public library (
lib/foo.dart
) from within its test (test/foo_test.dart
)?
pub
docs was written 4 years ago, whereas that part of Effective Dart was written 4 months ago, so the Effective Dart recommendation is more likely to be current. In general, as a centralized source for recommendations, Effective Dart is more visible and is more likely to follow currently recommended practices. – Sovranpub
documentation isn't supposed to be outdated. The documentation authors can't mark something with "This is outdated!" if they don't already know that it's outdated (and if they knew that, they could fix it or remove it instead). Accidental oversights happen, especially when there's a lot of documentation and when some things are documented in multiple places. And if some things weren't documented in multiple places, then information would be harder to find. – Sovran