Use existing thumbnail widget to render video thumbnails
This commit is contained in:
parent
5a6d36a369
commit
5424eb01f5
2 changed files with 16 additions and 15 deletions
|
@ -8,11 +8,12 @@ import 'package:photos/models/file_type.dart';
|
|||
import 'package:photos/ui/loading_widget.dart';
|
||||
|
||||
class ThumbnailWidget extends StatefulWidget {
|
||||
final File photo;
|
||||
|
||||
final File file;
|
||||
final BoxFit fit;
|
||||
const ThumbnailWidget(
|
||||
this.photo, {
|
||||
this.file, {
|
||||
Key key,
|
||||
this.fit = BoxFit.cover,
|
||||
}) : super(key: key);
|
||||
@override
|
||||
_ThumbnailWidgetState createState() => _ThumbnailWidgetState();
|
||||
|
@ -31,7 +32,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.photo.localId == null) {
|
||||
if (widget.file.localId == null) {
|
||||
return _getNetworkImage();
|
||||
}
|
||||
|
||||
|
@ -40,9 +41,9 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
if (_imageProvider != null) {
|
||||
final image = Image(
|
||||
image: _imageProvider,
|
||||
fit: BoxFit.cover,
|
||||
fit: widget.fit,
|
||||
);
|
||||
if (widget.photo.fileType == FileType.video) {
|
||||
if (widget.file.fileType == FileType.video) {
|
||||
content = Stack(
|
||||
children: [
|
||||
image,
|
||||
|
@ -70,12 +71,12 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
void _loadLocalImage(BuildContext context) {
|
||||
if (!_hasLoadedThumbnail && !_encounteredErrorLoadingThumbnail) {
|
||||
final cachedSmallThumbnail =
|
||||
ThumbnailLruCache.get(widget.photo, THUMBNAIL_SMALL_SIZE);
|
||||
ThumbnailLruCache.get(widget.file, THUMBNAIL_SMALL_SIZE);
|
||||
if (cachedSmallThumbnail != null) {
|
||||
_imageProvider = Image.memory(cachedSmallThumbnail).image;
|
||||
_hasLoadedThumbnail = true;
|
||||
} else {
|
||||
widget.photo.getAsset().then((asset) {
|
||||
widget.file.getAsset().then((asset) {
|
||||
asset
|
||||
.thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
|
||||
.then((data) {
|
||||
|
@ -90,7 +91,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
}
|
||||
});
|
||||
}
|
||||
ThumbnailLruCache.put(widget.photo, THUMBNAIL_SMALL_SIZE, data);
|
||||
ThumbnailLruCache.put(widget.file, THUMBNAIL_SMALL_SIZE, data);
|
||||
});
|
||||
}).catchError((e) {
|
||||
_logger.warning("Could not load image: ", e);
|
||||
|
@ -102,7 +103,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
|
||||
Widget _getNetworkImage() {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: widget.photo.getThumbnailUrl(),
|
||||
imageUrl: widget.file.getThumbnailUrl(),
|
||||
placeholder: (context, url) => loadWidget,
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fit: BoxFit.cover,
|
||||
|
@ -112,7 +113,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
@override
|
||||
void didUpdateWidget(ThumbnailWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.photo.generatedId != oldWidget.photo.generatedId) {
|
||||
if (widget.file.generatedId != oldWidget.file.generatedId) {
|
||||
setState(() {
|
||||
_hasLoadedThumbnail = false;
|
||||
_imageProvider = null;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/cache/thumbnail_cache.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/ui/thumbnail_widget.dart';
|
||||
import 'package:photos/ui/video_controls.dart';
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
@ -101,8 +101,8 @@ class _VideoWidgetState extends State<VideoWidget> {
|
|||
imageUrl: widget.file.getThumbnailUrl(),
|
||||
fit: BoxFit.contain,
|
||||
)
|
||||
: Image.memory(
|
||||
ThumbnailLruCache.get(widget.file, THUMBNAIL_SMALL_SIZE),
|
||||
: ThumbnailWidget(
|
||||
widget.file,
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
return Container(
|
||||
|
|
Loading…
Add table
Reference in a new issue