构建平台特定的UI(Android和Ios)错误:,'Widget',是一个潜在的不可空的类型


Widget getPicker() {
if (Platform.isAndroid) {
getDropdownButton();
} else if (Platform.isIOS) {
getCupertinoPicker();
}
}

error:主体可能正常完成,导致返回'null',但返回类型'Widget'可能是不可空的类型。我尝试使用return

Widget getPicker() {
if (Platform.isAndroid) {
return getDropdownButton();
} else if (Platform.isIOS) {
return getCupertinoPicker();
}
}

试试:

Widget getPicker() {
if (Platform.isAndroid) {
return getDropdownButton();
} else {
return getCupertinoPicker();
}
}

最新更新