I do not completely understand the difference between part
/part of
and import
/export
when using libraries in Dart. For e
Let's suppose we have a Dart library called mylib
, whose file is lib/mylib.dart
.
library mylib;
// Definitions
That library can be included in the main.dart
file as
import 'package:mypackage/mylib.dart';
When you create a new library and use other libraries you want to make available automatically when using your package, then you use export
:
library mylib;
export 'otherlib.dart';
// Definitions
You can use the show
keyword to import/export only some parts of a library (like a class or something).
You are using the part of
directive wrong here. You can't use both library
and part of
, which is used to specify the contents that belong to a library. For example, you can split your library file in more than one file (the parts):
Suppose we have in the file mylib.dart
:
library mylib;
part 'src/class1.part';
// More parts
And then we have in another file src/class1.part
the part specified in mylib.dart
part of mylib;
class Class1 {
/* ... */
}