Flutter Dart variables and constants

variable:

1. Specific type declarations can be used, such as String, int, List, bool

2. Uncertain types can use var, Object, dynamic keyword declaration

3. Object will be tested at compile time, dynamic will not.

constant:

1.final or const

2. The final modified variable can only be set once

3. A const variable is a compile-time constant, that is, it must be initialized when it is declared

4. Variables modified by final or const cannot be used with var at the same time, var needs to be omitted

final String book ='Flutter from entry to giving up';

final book ='Flutter from entry to giving up';

5. const defines compile-time constants and can only be initialized with compile-time constants

Final defined constants can be initialized with variables

final time = new DateTime.now(); //Ok

const time = new DateTime.now(); //Error, new DateTime.now() is not a const constant

 

Guess you like

Origin blog.csdn.net/qq_37980878/article/details/111469942