我试图用图像选择器插件连接我现有的屏幕。但由于某种原因,我得到了错误显示";无法将参数类型"Null"分配给参数类型"Function"我使用onSelectVideo和null-的按钮的代码
ElevatedButton(
child: Text(
'Next',
style: TextStyle(fontSize: 17, color: Colors.white),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => video_record02(
onSelectVideo: null,
),
),
);
},
),
现在问题是我知道我不需要在这里使用null。但是我不知道用什么来代替null。下一个屏幕的起始代码是这样的-
class video_record02 extends StatefulWidget {
final Function onSelectVideo;
const video_record02({Key? key, required this.onSelectVideo})
: super(key: key);
@override
_video_record02State createState() => _video_record02State();
}
class _video_record02State extends State<video_record02> {
File? storedImage;
Future<void> takeVideo() async {
final picker = ImagePicker();
final videoFile = await picker.pickVideo(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.rear,
maxDuration: Duration(
seconds: 25,
),
);
if (videoFile == null) {
return;
}
final rlyvideoFile = File(videoFile.path);
setState(() {
storedImage = rlyvideoFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(rlyvideoFile.path);
final savedImage = await rlyvideoFile.copy('${appDir.path}/$fileName');
widget.onSelectVideo(savedImage);
}
当我删除null时,它显示我需要一个标识符,但我无法使其工作。由于我是一个新手,如果你能帮我解决这个问题,我将不胜感激。
像onSelectedVideo:(savedImage){}
一样更改onSelectedVideo
上的null
ElevatedButton(
child: Text(
'Next',
style: TextStyle(fontSize: 17, color: Colors.white),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => video_record02(
onSelectVideo: (savedImage){
//fill some code you want to execute if the video was selected
},
),
),
);
},
),