I try to make my text responsivness, but I get the error:
'Desktop' is deprecated and shouldn't be used
'Mobile' is deprecated and shouldn't be used
Someone know why I can't use DeviceScreenType.Desktop and DeviceScreenType.Mobile? I tried to figure it out on my own, but I don't get it at all. I hope u can help me.
class CourseDetails extends StatelessWidget {
const CourseDetails({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ResponsiveBuilder(
builder: (context, sizingInformation) {
var textAlignment;
if (sizingInformation.deviceScreenType == DeviceScreenType.Desktop) {
textAlignment = TextAlign.left;
} else {
textAlignment = TextAlign.center;
}
double titleSize;
if (sizingInformation.deviceScreenType == DeviceScreenType.Mobile) {
titleSize = 50;
} else {
titleSize = 80;
}
double descriptionSize;
if (sizingInformation.deviceScreenType == DeviceScreenType.Mobile) {
descriptionSize = 16;
} else {
descriptionSize = 21;
}
CodePudding user response:
If you check the source code you can see what the deprecation warning is about:
enum DeviceScreenType {
@Deprecated('Use lowercase version')
Mobile,
@Deprecated('Use lowercase version')
Tablet,
@Deprecated('Use lowercase version')
Desktop,
@Deprecated('Use lowercase version')
Watch,
mobile,
tablet,
desktop,
watch
}
In short: Convert your enums to lowercase e.g.: DeviceScreenType.desktop