user15405245
user15405245

Reputation:

how could i use final in text value?

In some cases, programmers mark a text value as a final, does that mean that you can not change its value?

Sample of code:

final String textValue=" ";    

Upvotes: 1

Views: 667

Answers (2)

Jitesh Mohite
Jitesh Mohite

Reputation: 34210

Use late final which introduced in Flutter 2.0, which allows us to set final value at runtime, but only once

late final int value;
value = 5; 
print(value); // Working
value = 6;//Error: The late final local variable is already assigned.
          // Value will be assigned only once. 

Upvotes: 0

ypakala
ypakala

Reputation: 1209

Yes, A final variable can be set only once.

https://dart.dev/guides/language/language-tour#final-and-const

Note: Although a final object cannot be modified, its fields can be changed. In comparison, a const object and its fields cannot be changed: they’re immutable.

Upvotes: 1

Related Questions