Flutter - 参数类型 'Null' 无法分配给参数类型 'Function'
Flutter - The argument type 'Null' can't be assigned to the parameter type 'Function'
我试图将我现有的屏幕与图像选择器插件连接起来。但出于某种原因,我收到错误消息“无法将参数类型 '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 时,它显示我需要一个标识符,但我无法让它工作。由于本人是flutter学习新手,如果能帮我解决这个问题,我将不胜感激
像这样在 onSelectedVideo
上更改 null onSelectedVideo:(savedImage){}
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
},
),
),
);
},
),
我试图将我现有的屏幕与图像选择器插件连接起来。但出于某种原因,我收到错误消息“无法将参数类型 '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 时,它显示我需要一个标识符,但我无法让它工作。由于本人是flutter学习新手,如果能帮我解决这个问题,我将不胜感激
像这样在 onSelectedVideo
上更改 null onSelectedVideo:(savedImage){}
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
},
),
),
);
},
),