97 lines
2.9 KiB
Dart
97 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:f0ckapp/models/item.dart';
|
|
import 'package:f0ckapp/widgets/video_widget.dart';
|
|
|
|
class FullScreenMediaView extends StatefulWidget {
|
|
final MediaItem item;
|
|
final Duration? initialPosition;
|
|
|
|
const FullScreenMediaView({
|
|
super.key,
|
|
required this.item,
|
|
this.initialPosition,
|
|
});
|
|
|
|
@override
|
|
State createState() => _FullScreenMediaViewState();
|
|
}
|
|
|
|
class _FullScreenMediaViewState extends State<FullScreenMediaView> {
|
|
final GlobalKey<VideoWidgetState> _videoKey = GlobalKey<VideoWidgetState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
super.dispose();
|
|
}
|
|
|
|
void _popWithPosition() {
|
|
Duration? currentPosition;
|
|
if (widget.item.mime.startsWith('video') && _videoKey.currentState != null) {
|
|
currentPosition = _videoKey.currentState!.videoController.value.position;
|
|
}
|
|
Navigator.of(context).pop(currentPosition);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PopScope(
|
|
onPopInvokedWithResult: (bool didPop, Object? result) async {
|
|
return _popWithPosition();
|
|
},
|
|
child: Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: widget.item.mime.startsWith('image')
|
|
? InteractiveViewer(
|
|
minScale: 1.0,
|
|
maxScale: 7.0,
|
|
child: CachedNetworkImage(
|
|
imageUrl: widget.item.mediaUrl,
|
|
fit: BoxFit.contain,
|
|
placeholder: (context, url) =>
|
|
const Center(child: CircularProgressIndicator()),
|
|
errorWidget: (context, url, error) =>
|
|
const Icon(Icons.error),
|
|
),
|
|
)
|
|
: Center(
|
|
child: VideoWidget(
|
|
key: _videoKey,
|
|
details: widget.item,
|
|
isActive: true,
|
|
fullScreen: true,
|
|
initialPosition: widget.initialPosition,
|
|
),
|
|
),
|
|
),
|
|
SafeArea(
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: _popWithPosition,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|