簡體   English   中英

如何使用按鈕 Flutter 從屏幕中刪除選定的視頻

[英]How can i remove selected video from screen with button Flutter

我想從屏幕上刪除選定的視頻,我嘗試了不同的方法,但無法獲取這里是代碼:

視頻幀上有按鈕,所以當我點擊時我想從屏幕上刪除

if (_video != null) {
  _videoPlayerController.value.initialized
    ? Expanded(
        child: Stack(
          children: <Widget>[
            Container(
              height: 45,
              width: 47,
              child: AspectRatio(
                aspectRatio:
                  _videoPlayerController
                      .value
                      .aspectRatio,
                child: VideoPlayer(
                  _videoPlayerController
                ),
              ),
            ),
            Positioned(
              top: -15,
              right: -15,
              child: ClipRRect(
                borderRadius:
                  BorderRadius.circular(16.0),
                child: IconButton(
                  hoverColor: Colors.red,
                  icon: Icon(
                    Icons.delete,
                    color: Colors.red,
                    size: 23,
                  ),
                  onPressed: () => _removeVideo
                ),
              ),
            ),
          ],
        ),
      )
    : Container()
} else {
  Text(" ",
    style: TextStyle(fontSize: 18.0),
  ),
}


_pickVideo() async {
  File video = await ImagePicker.pickVideo(source: ImageSource.gallery);
  _video = video;
  _videoPlayerController = VideoPlayerController.file(_video)
    ..initialize().then((_) {
      setState(() {});
// _videoPlayerController.play();
    });
  }

這是我嘗試過的,我創建了函數但它不起作用

void _removeVideo() {
  _video.remove(_video);
  setState(() {
    _video = _video;
  });
}

根據您的代碼,您應該只需要執行以下操作:

void _removeVideo() {
  setState(() {
    _video = null;
  });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM