[英]In Flutter Is it possible to show the image and the video in the same widget, Are there any common widget?
我想在通用小部件中显示图像和视频,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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.