I am experimenting with my first Dart web app and do not expect to make any part of my app a reusable library for other apps/libs. As such, I do not have a lib
directory in my project; rather, I have a web
directory.
I guess my intent is to have my web
directory look like this:
web/
Main.dart <-- where my main method is
logging/
Logger.dart
LogLevel.dart
model/
Signin.dart
Signout.dart
view/
SigninView.dart
signinView.html
presenter/
SigninPresenter.dart
...lots of other packages
Several questions:
- Should my entire application (everything under
web
) be considered to be a part of the samelibrary
? If so, would I then putlibrary myapp;
at the top of every Dart file? Otherwise, what is the level of granularity for alibrary
? Should I put it package-level, and haveLogger
andLogLevel
insidelibrary logging;
? Is it at the class/file level and have alibrary logger
and alibrary log_level
? - Is my
web
directory set up correctly? I'm coming from Java so I'm treatingweb
the same as Java/Maven'ssrc/main/java
directory, and setting up a package structure underweb
that makes sense to me... - I understand that the
import
keyword is for importing source types from other packages. But what aboutexport
- what does that do?
I would recommend that you have a
lib/
directory and put shared code within it. If the code isn't directly to be used by other parts of your app, move that code to thesrc/
directory withinlib/
. I realize that you are not planning to make your app reusable by other apps, but code which is consumed by different parts of your app should probably live withinlib/
.A lot of this is a matter of convenience and convention, but I try to keep my
web/
directory pretty lean, even going so far as to place only those.dart
files in it that are directly referenced in a.html
file. Your mileage may vary, but I find that this convention (putting shared code inlib/
and web-specific code inweb/
helps keep things clear).As for library directives, I like to use a single namespace which is the same as the name of the app.
So, a library in
lib/models.dart
could be declared like this:A library in `web/foo/bar.dart' could be declared like this: