2

For Dart starters I'm working on a simple web which consists of less than 10 classes. I'm totally confused as for how to organized them in files, folders (and packages? and libraries?).

Currently I have

web/
  img/
    *.png
  styles/
    main.css
  index.html
  main.dart
  *.dart

All but one Dart file contain a single class. Imports are done through import 'a.dart'; (e.g. in b.dart).

This is obviously wrong because the Dart Editor complains about

The imported libraries 'c.dart' and 'd.dart' should not have the same name ''

I went through the respective sections in pub documentation and read about possible app structures in the Polymer docs. I also looked at the structure of the pop_pop_win sample application that comes with Dart. It's all a bit overwhelming because there are so many variations, options and combinations.

2
  • 1
    See stackoverflow.com/questions/16695634/…. It sounds like this is your real issue, not any problem with folder structure. Commented Feb 1, 2015 at 21:52
  • Thanks. So, if I got that right I can add library foo; part 'a.dart';... to main.dart and then add part of foo; to the other Dart files. Works, but means I have to have all imports in main.dart because part files can't have individual imports...not nice. Or I can add library X; to each Dart file. That's even worse because 1 class in 1 file doesn't make a "library" yet. Hhhmm, I feel there must be a better way... Commented Feb 1, 2015 at 22:53

1 Answer 1

1

If I were you, I would create libraries and imports like so:

awesomeLibrary.dart

library awesome;

part 'foo.dart';
part 'bar.dart';

foo.dart

part of awesome;

class Foo
{
    static function Baz() {}
}

bar.dart

part of awesome;

class Bar
{
    ...
}

main.dart

import 'awesomeLibrary.dart';

void main()
{
    Foo.Baz();  // Imported library function
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.