dart import and part of directives in same file

2019-08-08 18:06发布

问题:

I'm writing a dart file:

import 'something.dart'

part of my_lib;

class A{
    //...
}

I have tried this with the import and part of directives reversed and it still won't work, can you not have a class file as part of a library and have imports?

回答1:

All your imports should go in the file that defines the library.

Library:

library my_lib;

import 'something.dart';

part 'a.dart';

class MyLib {
  //...
}

a.dart

part of my_lib;

class A {
  //...
}

Since a.dart is part of my_lib it will have access to any files that my_lib imports.



标签: import dart