building platform specific UI (Android &Ios ) error : ,'Widget', is a potentially non-nullable type

27 Views Asked by At
Widget getPicker() {
  if (Platform.isAndroid) {
    getDropdownButton();
  } else if (Platform.isIOS) {
    getCupertinoPicker();
  }
}

error: The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type. i tried using return

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

There are 1 best solutions below

0
Siddharth Mehra On

Try this way:

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