Home > Net >  'Desktop' is deprecated and shouldn't be used (DeviceScreenType)
'Desktop' is deprecated and shouldn't be used (DeviceScreenType)

Time:05-27

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
}

https://github.com/FilledStacks/responsive_builder/blob/7ba6b5b13e784d654463c7c03f1a6186b7a137a7/lib/src/device_screen_type.dart

In short: Convert your enums to lowercase e.g.: DeviceScreenType.desktop

  • Related