【问题标题】:In Flutter Is it possible to show the image and the video in the same widget, Are there any common widget?在 Flutter 中是否可以在同一个小部件中显示图像和视频,有没有通用的小部件?
【发布时间】:2020-03-19 14:35:50
【问题描述】:

我想在通用小部件中显示图像和视频,flutter中有没有通用小部件来显示图像和视频。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我认为 Flutter 中没有任何此类小部件。

    您可以创建自定义小部件。PhotoVideoViewWidget如代码所示。

    
    class PhotoVideoViewWidget extends StatelessWidget {
      final String type;
      final String url;
    
      const PhotoVideoViewWidget({Key key, this.type, this.url}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return type == "video"
            ? VideoViewWidget(
                videoUrl: url,
              )
            : PhotoViewWidget(
                imageUrl: url,
              );
      }
    }
    
    class PhotoViewWidget extends StatelessWidget {
      final String imageUrl;
    
      const PhotoViewWidget({Key key, this.imageUrl}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return PhotoViewer(imageUrl);
      }
    }
    
    class VideoViewWidget extends StatelessWidget {
      final String videoUrl;
    
      const VideoViewWidget({Key key, this.videoUrl}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return VideoViewer(videoUrl);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2020-09-09
      • 1970-01-01
      • 2020-11-07
      • 2021-07-24
      • 2014-12-04
      • 2010-09-10
      • 1970-01-01
      • 2019-12-20
      相关资源
      最近更新 更多