我想在通用小部件中显示图像和视频,在颤动中是否有任何通用小部件来显示图像和视频。
答案 0 :(得分:1)
我认为内置的此类小部件不存在。
您可以创建自定义窗口小部件。 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);
}
}