'Desktop' 已弃用,不应使用 (DeviceScreenType)

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

我试图让我的文本响应,但我收到错误:

'Desktop' is deprecated and shouldn't be used
'Mobile' is deprecated and shouldn't be used

有人知道为什么我不能使用 DeviceScreenType.Desktop 和 DeviceScreenType.Mobile 吗? 我试图自己弄清楚,但我根本不明白。希望你能帮帮我。

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;
        }

如果您查看源代码,您可以看到弃用警告的内容:

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

简而言之:将您的枚举转换为小写,例如:DeviceScreenType.desktop