简体   繁体   中英

Error: Cannot run with sound null safety, because the following dependencies don't support null safety; in flutter

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(),
            ),
          );
        }
    );
  }

In Android Studio:

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

在此处输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM