I am debating whether to put an enum (that will be referenced in multiple classes and files within my src
folder) inside of one of the files in my src
directory or within the export file that sits under the lib folder. I want to expose the enum, but I also do not want the user to import files besides the entrance file. Would it make sense to put the enum inside the entrance file in this case? My directory structure looks like this:
lib/
entrance.dart <- Would here be ok?
src/
packages and files <- Or Does it have to be here?
You can do either.
If you declare the enum in a file under src/
, say src/enum.dart
, you can then export it from the entrance.dart
using export "src/enum.dart";
. Other users of the enum in src/
just need to import "enum.dart";
.
if you declare the enum in entrance.dart
, you don't have to bother with exporting it, but all files in src/
which uses the enum needs to import "../entrance.dart";
(maybe with a show
clause to avoid all the other things that are exported).
I'd personally go for the former approach, but either can work.