Maniak
Maniak

Reputation: 31

Flutter error while using late initializer

Im trying to connect my flutter web with discord oauth2 but i've got problem with late initializer.

Flutter suggests me to use "late" in:

Computed<ThemeData> _$currentThemeDataComputed;

After i add "late" then when im trying to run my website i've got this error:

LateInitializationError: Field '_$currentThemeDataComputed' has not been initialized.

Is there another way to fix it?

Upvotes: 0

Views: 118

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63594

I will prefer making data nullable. like DataType? nullableVariableName.

Computed<ThemeData>? _$currentThemeDataComputed;

Now you can check if the value is null or not while read it.

Dont use ! directly without check null. Better way of handling will be

if(nullableVariableName!=null){
  /// use this variable 
}

More about null-safety

Upvotes: 1

Related Questions