I have created a Flutter package and I am using it in my Flutter project.
The package has a class FirebaseAuthFlowState
located in ...core/firebase_auth_flow_state.dart
. A package’s "root" file with an export is located right in a lib
directory and exports FirebaseAuthFlowState
.
When I am going to use the class FirebaseAuthFlowState
in my Flutter project, my IDE (VS Code) whispers me two possible imports, both works:
package:firebase_auth_flow/core/firebase_auth_flow_state.dart
package:firebase_auth_flow/firebase_auth_flow.dart
My firebase_auth_flow.dart file
library firebase_auth_flow;
export 'package:firebase_auth_flow/core/firebase_auth_flow_state.dart'
show FirebaseAuthFlowState;
- I expect only
package:firebase_auth_flow/firebase_auth_flow.dart
import possible. - I expect no
...core/firebase_auth_flow_state.dart
visible from the Flutter project.
2
Answers
I’m not entirely sure, but I believe you should put files in
lib/src/
or a subdirectory of it to exclude them from the import suggestions.The way I figured this is because I looked how flutter itself does it for its classes. I took
ListView
as example and when trying to use it it has these suggestions:After choosing one of the imports, when Ctrl+clicking on
ListView
I found outListView
is actually located atSo I thought for myself "Can I actually directly import it from there?" and the answer is yes. I removed the suggested import and wrote this instead:
And this works as expected although the IDE gives the following warning
Which makes me think that it’s not normal to import from there and also why it doesn’t show up in the suggestions, so that’s probably the way to do it.
just simply put your files into
lib/src/
.