【发布时间】:2021-12-22 15:40:55
【问题描述】:
我试图将我现有的屏幕与图像选择器插件连接起来。但由于某种原因,我收到错误消息,显示“无法将参数类型‘Null’分配给参数类型‘函数’。” 我使用 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 navigation uiimagepickercontroller flutter-navigation flutter-android