
commit a80d48e19d05d6b9978cc293d5d3dd460c387d27 Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Mon Apr 20 08:34:50 2020 +0900 video: fixed status check commit d5af7cecd5c14c47b108456777da170052b7754f Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Sun Apr 19 22:13:58 2020 +0900 safer seek commit f84768dd9ac5a70a4489509bd944685298023550 Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Sun Apr 19 22:08:06 2020 +0900 use forked `flutter_ijkplayer` to support content URIs on Android < Q commit fde82bc213b0058cd990af2c7678f46b20c78bd7 Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Sun Apr 19 18:39:18 2020 +0900 packages upgrade commit 14414f32203a5caccdb61902ce75b0d83a1a8656 Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Sun Apr 19 14:57:38 2020 +0900 fixes for flutter_ijkplayer commit 2944d84d9f334bbe54303f7eb3b82a517664e84a Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Fri Apr 17 15:58:29 2020 +0900 draft for flutter_ijkplayer commit 0d82956b8e7e1d4500d09805a5d0fd59d2361ed3 Author: Thibault Deckers <thibault.deckers@gmail.com> Date: Fri Apr 17 13:00:14 2020 +0900 switch from video_player to fijkplayer
121 lines
4.5 KiB
Dart
121 lines
4.5 KiB
Dart
import 'package:aves/model/image_entry.dart';
|
|
import 'package:aves/utils/constants.dart';
|
|
import 'package:aves/widgets/common/image_providers/thumbnail_provider.dart';
|
|
import 'package:aves/widgets/common/image_providers/uri_image_provider.dart';
|
|
import 'package:aves/widgets/common/image_providers/uri_picture_provider.dart';
|
|
import 'package:aves/widgets/fullscreen/video_view.dart';
|
|
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:photo_view/photo_view.dart';
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
class ImageView extends StatelessWidget {
|
|
final ImageEntry entry;
|
|
final Object heroTag;
|
|
final ValueChanged<PhotoViewScaleState> onScaleChanged;
|
|
final VoidCallback onTap;
|
|
final List<Tuple2<String, IjkMediaController>> videoControllers;
|
|
|
|
const ImageView({
|
|
this.entry,
|
|
this.heroTag,
|
|
this.onScaleChanged,
|
|
this.onTap,
|
|
this.videoControllers,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
const backgroundDecoration = BoxDecoration(color: Colors.transparent);
|
|
|
|
// no hero for videos, as a typical video first frame is different from its thumbnail
|
|
|
|
if (entry.isVideo) {
|
|
final videoController = videoControllers.firstWhere((kv) => kv.item1 == entry.uri, orElse: () => null)?.item2;
|
|
return PhotoView.customChild(
|
|
child: videoController != null
|
|
? AvesVideo(
|
|
entry: entry,
|
|
controller: videoController,
|
|
)
|
|
: const SizedBox(),
|
|
backgroundDecoration: backgroundDecoration,
|
|
scaleStateChangedCallback: onScaleChanged,
|
|
minScale: PhotoViewComputedScale.contained,
|
|
initialScale: PhotoViewComputedScale.contained,
|
|
onTapUp: (tapContext, details, value) => onTap?.call(),
|
|
);
|
|
}
|
|
|
|
// if the hero tag is defined in the `loadingBuilder` and also set by the `heroAttributes`,
|
|
// the route transition becomes visible if the final is loaded before the hero animation is done.
|
|
|
|
// if the hero tag wraps the whole `PhotoView` and the `loadingBuilder` is not provided,
|
|
// there's a black frame between the hero animation and the final image, even when it's cached.
|
|
|
|
final thumbnailLoadingBuilder = (context) => Center(
|
|
child: AspectRatio(
|
|
// enforce original aspect ratio, as some thumbnails aspect ratios slightly differ
|
|
aspectRatio: entry.displayAspectRatio,
|
|
child: Image(
|
|
image: ThumbnailProvider(
|
|
entry: entry,
|
|
extent: Constants.thumbnailCacheExtent,
|
|
),
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget child;
|
|
if (entry.isSvg) {
|
|
child = PhotoView.customChild(
|
|
child: SvgPicture(
|
|
UriPicture(
|
|
uri: entry.uri,
|
|
mimeType: entry.mimeType,
|
|
colorFilter: Constants.svgColorFilter,
|
|
),
|
|
placeholderBuilder: thumbnailLoadingBuilder,
|
|
),
|
|
backgroundDecoration: backgroundDecoration,
|
|
scaleStateChangedCallback: onScaleChanged,
|
|
minScale: PhotoViewComputedScale.contained,
|
|
initialScale: PhotoViewComputedScale.contained,
|
|
onTapUp: (tapContext, details, value) => onTap?.call(),
|
|
);
|
|
} else {
|
|
final uriImage = UriImage(
|
|
uri: entry.uri,
|
|
mimeType: entry.mimeType,
|
|
);
|
|
child = PhotoView(
|
|
// key includes size and orientation to refresh when the image is rotated
|
|
key: ValueKey('${entry.orientationDegrees}_${entry.width}_${entry.height}_${entry.path}'),
|
|
imageProvider: uriImage,
|
|
// when the full image is ready, we use it in the `loadingBuilder`
|
|
// we still provide a `loadingBuilder` in that case to avoid a black frame after hero animation
|
|
loadingBuilder: (context, event) => imageCache.statusForKey(uriImage).keepAlive
|
|
? Image(
|
|
image: uriImage,
|
|
)
|
|
: thumbnailLoadingBuilder(context),
|
|
backgroundDecoration: backgroundDecoration,
|
|
scaleStateChangedCallback: onScaleChanged,
|
|
minScale: PhotoViewComputedScale.contained,
|
|
initialScale: PhotoViewComputedScale.contained,
|
|
onTapUp: (tapContext, details, value) => onTap?.call(),
|
|
filterQuality: FilterQuality.low,
|
|
);
|
|
}
|
|
|
|
return heroTag != null
|
|
? Hero(
|
|
tag: heroTag,
|
|
transitionOnUserGestures: true,
|
|
child: child,
|
|
)
|
|
: child;
|
|
}
|
|
}
|