我试图使我的文本响应性,但我得到错误:
'Desktop' is deprecated and shouldn't be used
'Mobile' is deprecated and shouldn't be used
有人知道为什么我不能使用DeviceScreenType。桌面和devicescreenttype . 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