I have created a seperate class "DirectionDetails" which is;
class DirectionDetails{
int distanceValue;
int durationValue;
String distanceText;
String durationText;
String encodedPoints;
DirectionDetails(this.distanceValue, this.durationValue, this.distanceText, this.durationText, this.encodedPoints);
}
When I try to initialize that in the main class by DirectionDetails tripDirectionDetails;
, it gives the
Non-nullable instance field 'tripDirectionDetails' must be initialized
error. But as it suggest, when I add "late" modifier - it dosen't show any errors but when i run the app it gives the,
LateInitializationError: Field 'tripDirectionDetails' has not been initialized.
runtime error
There is an alternative method I tried, when i try to initialize tripDirectionDetails
in main class using,
DirectionDetails tripDirectionDetails = new DirectionDetails();
and modify DirectionDetails
class by,
class DirectionDetails{
int distanceValue;
int durationValue;
String distanceText;
String durationText;
String encodedPoints;
DirectionDetails({this.distanceValue = 0, this.durationValue = 0, this.distanceText = "", this.durationText = "", this.encodedPoints = ""});
}
App runs successfully, it retrieves all the vales in "DirectionDetails" class only for the initial reboot.
But when I exit the app and come back, it gives the following error.
LateInitializationError: Field 'tripDirectionDetails' has not been initialized.
Your help is much appreciated.
Thank you