问题描述
今天在学习别人代码时,报了一个如下错误:
/D:/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:4:1: Error: A library can't opt out of null safety by default, when using sound null safety. // @dart = 2.8 ^^^^^^^^^^^^^^ Error: Cannot run with sound null safety, because the following dependencies don't support null safety: package:camera package:story_view package:flutter_cache_manager package:video_player package:rxdart package:video_player_platform_interface
原因分析
程序是按照完全空值安全的规则跑的,但是你用的库里有不支持控制安全的库。
解决方法
1、在main.dart 文件的最前面加上 // @dart=2.9
如下图
// @dart=2.9 import 'package:flutter/material.dart'; void main() { //... }
2、如果你是用命令的形式运行的可以直接加上如下参数
flutter run --no-sound-null-safety