You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when setting up the background image using the ternary operator, if a user does not have an internet connection it causes the app to crash instead of displaying the info 'Could not get time data'. Although a try and catch block was added to the world_time.dart class to prevent the app from crashing when it fails to fetch json data, the boolean variable which is 'isDaytime' would be null because it would skip the try block and when it is being called in the loading.dart file it would have a value of null which would cause another exception in the home.dart file when setting the bgImage variable which depends on the isDaytime variable.
The code below should be added to home.dart file just above the scaffold widget
String bgImage;
//isDayTime can be null if time data is not found (no internet connection)
if(data['isDayTime'] != null){
//set background image
bgImage = data['isDayTime'] ? 'day.png' : 'night.png';
}else{
//set the bgImage to 'day.png'
bgImage = 'day.png';
}
The text was updated successfully, but these errors were encountered:
from lesson 33
when setting up the background image using the ternary operator, if a user does not have an internet connection it causes the app to crash instead of displaying the info 'Could not get time data'. Although a try and catch block was added to the world_time.dart class to prevent the app from crashing when it fails to fetch json data, the boolean variable which is 'isDaytime' would be null because it would skip the try block and when it is being called in the loading.dart file it would have a value of null which would cause another exception in the home.dart file when setting the bgImage variable which depends on the isDaytime variable.
The code below should be added to home.dart file just above the scaffold widget
String bgImage;
//isDayTime can be null if time data is not found (no internet connection)
if(data['isDayTime'] != null){
//set background image
bgImage = data['isDayTime'] ? 'day.png' : 'night.png';
}else{
//set the bgImage to 'day.png'
bgImage = 'day.png';
}
The text was updated successfully, but these errors were encountered: