Pages

Saturday 2 July 2016

Importing Custom Libraries in Dart

After several months of using Dart to develop virtually real solutions, I started experimenting with class object programming. I have used classes extensively in another favourite programming languages such as Free Pascal, so it was only a matter of time until I started implementing these in Dart.

In my code, I initially had the custom class definition together with the main application code. This simplified understanding and trialing the concepts involved. As the class definition increased both in size and complexity, it made perfect sense to move out the class definitions into a dedicated class file.
This was relatively easy and presented no challenges in having the resultant application code function as was required. In other words, the importing of the new class definition file into teh main code was rather straightforward.

Invariably the class definitions continue to evolve and adapt to the application development requirements of one or more projects. I had started to create two additional class, each code in its own .dart file. It should go without saying on the advantages of breaking class definitions into their own files:
  • Object oriented paradigm.
  • Inheritance
  • Interface



All went well in creating the new class definition files when I suddenly could not proceed testing teh code due an unfamiliaar error in the editor:
The imported libraries 'libAdministration.dart' and 'libAdminReports.dart' cannot both be unnamed
Well, firstly I could not make sense of the message. Secondly, I did not know how to resolve this clearly phrased message, though a mouthful in some way. Thirdly, I asked myself - should I perhaps place all the class definition back into the main doe file?

Giving up easily is not in my nature, so after searching in google for a possible solution, I was excited that the solution was rather simple: at the top of each library file to be imported, add the following:
library libraryname;
 Thereafter my custom class definition file imports work without any problems.

No comments:

Post a Comment