Home > OS >  Error: Cannot run with sound null safety, because the following dependencies don't support null
Error: Cannot run with sound null safety, because the following dependencies don't support null

Time:09-08

i made a BlocBuilder and then this package can't run with null safety datetime_picker_formfield, i confuse how to fix the error and solve the error, this is the whole code of BlocBuilder:

      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) async {
              await showCupertinoModalPopup(
                  context: context,
                  builder: (context) {
                    return BottomSheet(
                      builder: (context) => Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Container(
                            constraints: BoxConstraints(maxHeight: 200),
                            child: CupertinoDatePicker(
                              onDateTimeChanged: (value) {
                                inputFieldBloc.updateValue;
                                 },
                            ),
                          ),
                          TextButton(onPressed: () => Navigator.pop(context), child: 
                        Text('Ok')),
                        ],
                      ),
                      onClosing: () {},
                    );
                  });
              //setState(() {});
              return value;;
            },
            decoration: InputDecoration(
              labelText: labelText,
              prefixIcon: Icon(Icons.calendar_today),
              border: OutlineInputBorder(),
            ),
          );
        }
    );

the code that contains import from the dependencies is return DateTimeField can anyone solve and find the error? i need your help, in case if you need to see the full code:

class CuppertinoDatePickerBlocBuilder extends StatelessWidget {
  CuppertinoDatePickerBlocBuilder({
    Key? key, required this.inputFieldBloc, required this.labelText,}) : super(key: key);


  //var screen = MediaQuery.of(context).size;
    DateTime value = DateTime.now();
    final InputFieldBloc<DateTime?, dynamic> inputFieldBloc;
    final String labelText;

  @override
  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) async {
              await showCupertinoModalPopup(
                  context: context,
                  builder: (context) {
                    return BottomSheet(
                      builder: (context) => Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Container(
                            constraints: BoxConstraints(maxHeight: 200),
                            child: CupertinoDatePicker(
                              onDateTimeChanged: (value) {
                                inputFieldBloc.updateValue;
                                 },
                            ),
                          ),
                          TextButton(onPressed: () => Navigator.pop(context), child: Text('Ok')),
                        ],
                      ),
                      onClosing: () {},
                    );
                  });
              //setState(() {});
              return value;;
            },
            decoration: InputDecoration(
              labelText: labelText,
              prefixIcon: Icon(Icons.calendar_today),
              border: OutlineInputBorder(),
            ),
          );
        }
    );
  }

CodePudding user response:

In Android Studio:

Run → Edit Configurations → Add Additional Run args → --no-sound-null-safety

enter image description here

CodePudding user response:

datetime_picker_formfield has null safe enabled. It seems you have to update the datetime_picker_formfield package version in pubspec.yaml.

The latest nulls datetime_picker_formfield version is 2.0.1

Example

dependencies:
    datetime_picker_formfield: ^2.0.1

CodePudding user response:

seems like your package needs to be updated please make sure when you run your code your package should be updated

datetime_picker_formfield: ^2.0.1

use this package in your pubspec yaml if you face any issue in your code and you want to use your old code please hit this command

flutter run --no-sound-null-safety

  • Related