Recipe-App---Flutter-UI
Recipe-App---Flutter-UI copied to clipboard
Support for Null-safety!
Some of the code doesn't work when we use Null-Safety.
For example (size_config.dart):
import 'package:flutter/widgets.dart';
class SizeConfig {
static MediaQueryData _mediaQueryData;
static double screenWidth;
static double screenHeight;
static double defaultSize;
static Orientation orientation;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
orientation = _mediaQueryData.orientation;
// On iPhone 11 the defaultSize = 10 almost
// So if the screen size increase or decrease then our defaultSize also vary
defaultSize = orientation == Orientation.landscape
? screenHeight * 0.024
: screenWidth * 0.024;
}
}
The non-nullable variable '_mediaQueryData' must be initialized. Try adding an initializer expression.
Using late keyword will solve the issue!
Because of null safety your variable must be initialzied when created, to fix this you can use late to tell it that it will be initialized after being created but before being used.
Yes, I was beginner at that time, now I understand.