从 const String 声明 const String
Declare const String from const String
const String IP_ADDRESS = "http://192.168.1.103:8088/";
const String HOME_EXPECTED = IP_ADDRESS + "index.html";
此代码 returns 来自 Dart 编辑器的意外错误消息。
An expression of type 'num' was expected
为什么?我该如何解决?
我尝试使用 'final'、'final const' 和静态。但失败了:(
我不懂这种语言'Dart'但是看了语言描述,使用'const':
是不可能达到你想要的效果的
Use const for variables that you want to be compile-time constants. If the const variable is at the class level, mark it static const. (Instance variables can’t be const.) Where you declare the variable, set the value to a compile-time constant such as a literal, a const variable, or the result of an arithmetic operation on constant numbers.
您的第二个变量声明不是文字,不是对另一个常量变量的简单赋值,也不是此类的算术运算。
来源: https://www.dartlang.org/docs/dart-up-and-running/ch02.html
更新
So String+ String is a constant (and has been for a while). String* int isn't and is not expected to be.
原创
在 Dart 中,构造常量的方式非常有限。 String 上的 +
运算符未列入创建 const 的白名单。
试试这个:
const String HOME_EXPECTED = "${IP_ADDRESS}index.html";
或
final String HOME_EXPECTED = IP_ADDRESS + "index.html";
如果不需要 const。
const String IP_ADDRESS = "http://192.168.1.103:8088/";
const String HOME_EXPECTED = IP_ADDRESS + "index.html";
此代码 returns 来自 Dart 编辑器的意外错误消息。
An expression of type 'num' was expected
为什么?我该如何解决?
我尝试使用 'final'、'final const' 和静态。但失败了:(
我不懂这种语言'Dart'但是看了语言描述,使用'const':
是不可能达到你想要的效果的Use const for variables that you want to be compile-time constants. If the const variable is at the class level, mark it static const. (Instance variables can’t be const.) Where you declare the variable, set the value to a compile-time constant such as a literal, a const variable, or the result of an arithmetic operation on constant numbers.
您的第二个变量声明不是文字,不是对另一个常量变量的简单赋值,也不是此类的算术运算。
来源: https://www.dartlang.org/docs/dart-up-and-running/ch02.html
更新
So String+ String is a constant (and has been for a while). String* int isn't and is not expected to be.
原创
在 Dart 中,构造常量的方式非常有限。 String 上的 +
运算符未列入创建 const 的白名单。
试试这个:
const String HOME_EXPECTED = "${IP_ADDRESS}index.html";
或
final String HOME_EXPECTED = IP_ADDRESS + "index.html";
如果不需要 const。