Home > Software engineering >  The body might complete normally, causing 'null' to be returned, but the return type, 
The body might complete normally, causing 'null' to be returned, but the return type, 

Time:09-13

I made a bloc builder that implemented form_bloc and i change the date-picker widget to ios style by using cupertino this code/body is showing error alert that it might causing null to be returned, the code:

            onShowPicker: (context, currentValue) {
              _showDialog(
                CupertinoDatePicker(
                  initialDateTime: value,
                  mode: CupertinoDatePickerMode.date,
                  use24hFormat: true,
                  // This is called when the user changes the date.
                  onDateTimeChanged: (value) {
                    setState(() => inputFieldBloc.updateValue);
                  },
                ),
              );
            },

and this is the whole code of build method:

Widget build(BuildContext context) {
    return BlocBuilder<InputFieldBloc, InputFieldBlocState>(
        bloc: inputFieldBloc,
        builder: (context, state) {
          return DateTimeField(
            format: DateFormat("dd-MM-yyyy"),
            initialValue: state.value,
            resetIcon: null,
            onChanged: (value) {
              inputFieldBloc.updateValue(value);
            },
            onShowPicker: (context, currentValue) {
              _showDialog(
                CupertinoDatePicker(
                  initialDateTime: value,
                  mode: CupertinoDatePickerMode.date,
                  use24hFormat: true,
                  // This is called when the user changes the date.
                  onDateTimeChanged: (value) {
                    setState(() => inputFieldBloc.updateValue);
                  },
                ),
              );
            },
            decoration: InputDecoration(
              labelText: labelText,
              prefixIcon: Icon(Icons.calendar_today),
              border: OutlineInputBorder(),
            ),
          );
        }
    );
  }

i put onShowPicker inside DateTimeField, do anyone know how to solve this error? i really need your help

CodePudding user response:

you miss the return

onShowPicker: (context, currentValue) {
          return something()

here another same issue https://stackoverflow.com/a/66873806/12838877

  • Related