I met an error when exporting two libraries. And these libraries have exactly same class name.
File: A.dart
library chrome.A; class MyClass { ... }
File: B.dart
library chrome.B; class MyClass { .. }
File: C.dart
library chrome_app; export 'A.dart'; export 'B.dart'; // HERE!! error message for the element 'MyClass' which is defined in the libraries 'A.dart' and 'B.dart'
Is this the intended result?
I think A.dart
and B.dart
has their own namespace so that there should be no error.
To import two classes with the same name, use the as keyword to rename one or both of the imports, e.g. import {Employee as Employee2} from './another-file-2. js'; . The as keyword allows us to change the identifying name of the import.
Yes, you can have two classes with the same name in multiple packages. However, you can't import both classes in the same file using two import statements. You'll have to fully qualify one of the class names if you really need to reference both of them.
Yes, It is allowed to define a method with the same name as that of a class. There is no compile-time or runtime error will occur. But this is not recommended as per coding standards in Java. Normally the constructor name and class name always the same in Java.
Exports the current Flutter internationalisation files to a singl CSV so that all translations can be worked on in on document. Once translation is complete, you can then use CreateCommand to generate new arb files to use in your Flutter project.
A library name isn't a namespace. Dart doesn't have namespaces.
What you can do in Dart is to specify a prefix for an import.
You have to import those libraries separately if you want to use them in the same library instead of just one import with import 'C.dart;'
import 'A.dart' as a; import 'B.dart' as b; var m = a.MyClass(); var n = b.MyClass();
If you just want to avoid the conflict and don't need both classes exported you can.
library chrome_app; export 'A.dart'; export 'B.dart' hide MyClass; // or export 'B.dart' show MyOtherClass, AnotherOne; // define explicitly which classes to export and omit MyClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With