const String IP_ADDRESS = "http://192.168.1.103:8088/";
const String HOME_EXPECTED = IP_ADDRESS + "index.html";
This code returns unexpected error message from Dart Editor.
An expression of type 'num' was expected
Why? and how can I fix it?
I tried using 'final', 'final const', and static. but failed :(
To define a string constant in C++, you have to include the string header library, then create the string constant using this class and the const keyword.
C string constants can be declared using either pointer syntax or array syntax: // Option 1: using pointer syntax. const char *ptr = "Lorem ipsum"; // Option 2: using array syntax.
You can use the #define directive to define a string constant.
Note also that you cannot use the const keyword to create a constant object. The const keyword can only be applied to the primitive data types (such as ints, floats, chars, and booleans) and strings. Let's understand the use of const with an example.
Update
http://dartbug.com/15853 says
So String+ String is a constant (and has been for a while). String* int isn't and is not expected to be.
I created http://dartbug.com/22408
Original
In Dart it is very limited how you can construct consts. The +
operator on String isn't whitelisted for const creation.
Try this instead:
const String HOME_EXPECTED = "${IP_ADDRESS}index.html";
or
final String HOME_EXPECTED = IP_ADDRESS + "index.html";
if const is not required.
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