简体   繁体   English

错误:无法以健全的 null 安全运行,因为以下依赖项不支持 null 安全; 在 flutter

[英]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 :我做了一个BlocBuilder ,然后这个 package 不能与 null 安全datetime_picker_formfield一起运行,我混淆了如何修复错误和解决错误,这是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?包含从依赖项导入的代码是return DateTimeField任何人都可以解决并找到错误吗? 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:在 Android 工作室中:

Run → Edit Configurations → Add Additional Run args → --no-sound-null-safety运行 → 编辑配置 → 添加额外的运行参数 → --no-sound-null-safety

在此处输入图像描述

datetime_picker_formfield has null safe enabled. datetime_picker_formfield启用了 null 安全。 It seems you have to update the datetime_picker_formfield package version in pubspec.yaml .看来您必须更新 pubspec.yaml 中的datetime_picker_formfield pubspec.yaml版本。

The latest nulls datetime_picker_formfield version is 2.0.1最新的 nulls datetime_picker_formfield 版本是 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似乎您的 package 需要更新请确保在运行代码时您的 package 应该更新

datetime_picker_formfield: ^2.0.1 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如果您在代码中遇到任何问题并且想要使用旧代码,请在您的 pubspec yaml 中使用此 package,请点击此命令

flutter run --no-sound-null-safety flutter 运行 --no-sound-null-safety

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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