If you want to reference another file in Dart? You will be importing the filename.dart and not the name of your library. So if the name of your library is: myLib and it is saved in the file: someDartFile.dart.
Here is a quick example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | //TestLib.dart import 'LibFile.dart'; //SomeLibrary void main() { print("Hello, World!"); LibFile l = new LibFile(); print(l.publicString);//public print(l.getPrivateString);//private print(l.getMagicNumber); //42 } //LibFile.dart library SomeLibrary; part 'LibFile2.dart'; class LibFile { String _privateString = "private"; String publicString = "public"; String get getPrivateString => _privateString; int get getMagicNumber => new LibFile2().number; } //LibFile2.dart part of SomeLibrary; class LibFile2 { int number = 42; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.