我試圖將我現有的螢屏與影像選擇器插件連接起來。但出于某種原因,我收到錯誤訊息,顯示“無法將引數型別‘空’分配給引數型別‘功能’。” 我使用 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 的新手,如果您能幫我解決這個問題,我將不勝感激。
uj5u.com熱心網友回復:
onSelectedVideo像這樣更改空值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
},
),
),
);
},
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/355073.html
標籤:扑 导航 uiimagepickercontroller 颤动导航 颤振机器人
上一篇:顫動前導動作后面的選項卡
