【发布时间】:2020-03-19 14:35:50
【问题描述】:
我想在通用小部件中显示图像和视频,flutter中有没有通用小部件来显示图像和视频。
【问题讨论】:
我想在通用小部件中显示图像和视频,flutter中有没有通用小部件来显示图像和视频。
【问题讨论】:
我认为 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);
}
}
【讨论】: