Home > other >  Flutter error while using late initializer
Flutter error while using late initializer

Time:12-11

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?

CodePudding user response:

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

  • Related