android - flutter中如何定义变量和常量?

标签 android android-studio flutter dart

正如我们在 swift 中定义的

常量与let

带有var的变量

如何在flutter中定义?

最佳答案

变量:

var number = 42;

常量:

If you never intend to change a variable, use final or const, either instead of var or in addition to a type. A final variable can be set only once; a const variable is a compile-time constant. (Const variables are implicitly final.) A final top-level or class variable is initialized the first time it’s used.

final name = 'Bob'; // Without a type annotation
final String nickname = 'Bobby';

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. Where you declare the variable, set the value to a compile-time constant such as a number or string literal, a const variable, or the result of an arithmetic operation on constant numbers:

const bar = 1000000; // Unit of pressure (dynes/cm2)
const double atm = 1.01325 * bar; // Standard atmosphere

更多信息请参见:https://dart.dev/guides/language/language-tour#variables

关于android - flutter中如何定义变量和常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57966620/

相关文章:

android - 如何使用Azure DevOps在Gradle Kotlin中生成和发布代码覆盖率?

android - 自定义 Navigationview 菜单 UI Android

android - 如何在android studio中使用fabric插件安装twitter kit

flutter - 为什么这个循环只发生一次? flutter/Dart

firebase - 如何从列表元素中获取单个值

android - WebView 缩放按钮 Controller

android - Android 布局中的十六进制颜色值未准确显示

java - Android NFC 读卡器给出 "avc: denied"

java - Android Studio : Could not determine Java version using executable C:\Program Files\Java\jdk-10\bin\java. 可执行文件

flutter - 每 500 毫秒自动递增 flutter