from wisconsion1 import *
from alaska1 import *
from texas1 import *
from indiana1 import *
Is there some way to simplify this? Esp if I'm going to add more in the future.
Yes, you can simplify and clean up the code it as follows:
import * from wisconsion1, alaska1, texas1, indiana1
Related
Using intl package how can I initialize multiple libraries. For example I have some translation on lib1 and other on lib2, I would like to initialize both translations so they can be used in my code. Until the moment I have this:
import 'package:lib1/_l10n/messages_all.dart' as lib1;
import 'package:lib2/_l10n/messages_all.dart' as lib2;
import 'package:intl/intl.dart';
import 'package:mylib/_l10n/messages_all.dart' as mylib;
main() {
intl.defaultLocle = 'es';
await lib1.initializeMessages('es');
await lib2.initializeMessages('es');
await mylib.initializeMessages('es');
print(lib1.helloMessage());
print(lib2.hiMessage());
print(mylib.whatUpMessage());
}
It only translate lib1.helloMessage() since is the first one, the rest of message keep being shown in english.
That doesn't work right now. You would have to generate a combined library and use that.
I have this code method in a java class with JAX-RS:
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
#Path("/reports/{id: (zerotrips|notrips|tripsummary|rejectedtrips){1}/{0,1}}")
#GET
public Response get(#Context HttpServletRequest aRequest){
....
}
Could someone give some examples of the url mapped by the expression in the #Path annotation?
/reports/zerotrips
/reports/zerotrips/
Replace zerotrips with any of the other ones on between the parenthesis
(zerotrips|notrips|tripsummary|rejectedtrips){1}
This says any one of the values in the parenthesis. | means "or". The {1} means "once".
/{0,1}
means with or without a slash. {0,1} means zero to once.
A pattern followed by {} gives the number of times it is allowed. For example a{3,5} means an a three to five times. So the following would match: aaa, aaaa, aaaaa, but aa would not match.
I have lets say two game projects: zoo 1 and zoo 2. Both have a class named animal. In order to avoid conflicts between the two classes with the same name I wrap them in functions. How does Dart handle such a scenario? Through packages or libraries? A master class used as a namespace? If so then how does it convert those to javascript?
Dart doesn't have namespaces. You can use import prefixes for that
import 'package:zoo1/zoo1.dart' as zoo1;
import 'package:zoo2/zoo2.dart' as zoo2;
main() {
print(new zoo1.Animal());
print(new zoo2.Animal());
}
you can also use the prefix only for one of these
import 'package:zoo1/zoo1.dart';
import 'package:zoo2/zoo2.dart' as zoo2;
main() {
print(new Animal());
print(new zoo2.Animal());
}
if you want to import both but only want to use Animal from zoo2 then you can hide one
import 'package:zoo1/zoo1.dart' hide Animal;
import 'package:zoo2/zoo2.dart';
main() {
print(new Animal()); // uses Animal from zoo2
}
I assume for JS they always use some prefix to disambiguate.
import "dart:html";
class ParentClass {
}
import "ParentClass";
class ChildClass extends ParentClass {
int main() {
Element e = querySelector()
}
}
Element & querySelector in ChildClass display as issues (Undefined Element & querySelector)
Is it not possible to import packages from ParentClass?
An import's scope is only the importing library.
If you import dart:html in the ParentClass library file and import the ParentClass library in another file, then the other file does not see the dart:html declarations.
There is two ways to handle that:
Preferably, just import dart:html in the other library too.
Export dart:html from the ParentClass library: add export "dart:html"; next to import "dart:html";. That way the declarations of dart:html will be available to any library importing ParentClass.
I am creating a scientific calc app in DART . i dont knw how to use trignometric functions like sine , cosine . i used "math.sin()" , but it throws an exception "NO top-level getter math.get declared " how to solve it ? thanks in advance
To use trigonometric functions in Dart, import the dart:math library. For example:
import 'dart:math';
main() {
print(sin(pi));
}
If you want, you can import with a prefix to avoid namespace collisions:
import 'dart:math' as Math;
main() {
print(Math.sin(Math.pi));
}