-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
In dart-lang/language#4112 one technique discussed/suggested is to export
a library with show
/hide
.
and then import that everywhere you would otherwise
import package:flutter/material.dart
.I think we need improved tooling for this.
When I once attempted something similar, the inconvenience of needing to select the correct import - and needing to remember it - is not great.
Perhaps we should have some kind of annotation we could use to say that "this export is preferred over importing directly"? Or perhaps that should be its own issue? I'm not sure where it would go though.
Originally posted by @TekExplorer in dart-lang/language#4112 (comment)
In my company, we have an internal rule. Say we have the following project structure:
lib/
├── a.dart
├── b.dart
├── f1/
│ ├── a1.dart
│ ├── b1.dart
│ └── f1.dart // barrel file exporting a1, b1
└── f2/
├── a2.dart
├── b2.dart
├── f2.dart // barrel file exporting a2, b2, f3/f3
└── f3/
├── a3.dart
└── f3.dart // barrel file exporting a3
- If we are in either
a
orb
, we'd import the barrel files forf1
orf2
. - If we are in
a1
and we need something fromb1
we'd import it directly, if we need anything else we'd import the closest file with that declaration (meaninga
,b
orf2/f2
) - If we are in
a2
we'd follow the same rule as above (for files insidef3
we'd import its barrel) - If we are in
f3
we'd import only barrel files ora
/b
.
I'm sure other projects have other rules for this but the point stands that importing the right file is a bit hard and a better tool for this would be a great addition!
Not sure what to suggest besides the above but I'm opening this as a place for this conversation.
P.S.: If this is not the right place to open this please say so.