Compare commits

...

5 Commits

Author SHA1 Message Date
5e8983e347 v1.4.9+70
All checks were successful
Flutter Schmutter / build (push) Successful in 3m39s
2025-06-24 14:19:41 +02:00
93a89ba4b9 .. 2025-06-24 13:05:08 +02:00
ba7505c2b3 v1.4.8+69
All checks were successful
Flutter Schmutter / build (push) Successful in 3m39s
2025-06-24 03:02:39 +02:00
39fadc009f ... 2025-06-24 02:21:06 +02:00
0d42fad708 v1.4.7+68
All checks were successful
Flutter Schmutter / build (push) Successful in 3m37s
2025-06-23 16:32:15 +02:00
11 changed files with 763 additions and 541 deletions

View File

@ -41,7 +41,7 @@ jobs:
TAR_OPTIONS: --no-same-owner TAR_OPTIONS: --no-same-owner
- name: build apk - name: build apk
run: flutter build apk --release run: flutter build apk --release --split-per-abi
- name: release-build - name: release-build
uses: akkuman/gitea-release-action@v1 uses: akkuman/gitea-release-action@v1
@ -49,7 +49,9 @@ jobs:
NODE_OPTIONS: '--experimental-fetch' NODE_OPTIONS: '--experimental-fetch'
with: with:
files: |- files: |-
build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk
build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
build/app/outputs/flutter-apk/app-x86_64-release.apk
token: '${{secrets.RELEASE_TOKEN}}' token: '${{secrets.RELEASE_TOKEN}}'
- name: upload apk to f-droid server - name: upload apk to f-droid server
@ -57,5 +59,5 @@ jobs:
BUILD_NUMBER=$(grep '^version:' pubspec.yaml | sed 's/.*+//') BUILD_NUMBER=$(grep '^version:' pubspec.yaml | sed 's/.*+//')
curl -X POST "https://flumm.io/pullfdroid.php" \ curl -X POST "https://flumm.io/pullfdroid.php" \
-F "token=${{ secrets.PULLER_TOKEN }}" \ -F "token=${{ secrets.PULLER_TOKEN }}" \
-F "apk=@build/app/outputs/flutter-apk/app-release.apk" \ -F "apk=@build/app/outputs/flutter-apk/app-arm64-v8a-release.apk" \
-F "build=$BUILD_NUMBER" -F "build=$BUILD_NUMBER"

View File

@ -14,6 +14,7 @@ class MediaController extends GetxController {
RxBool loading = false.obs; RxBool loading = false.obs;
RxBool atEnd = false.obs; RxBool atEnd = false.obs;
RxBool atStart = false.obs; RxBool atStart = false.obs;
Rxn<String> errorMessage = Rxn<String>();
RxInt typeIndex = 0.obs; RxInt typeIndex = 0.obs;
RxInt modeIndex = 0.obs; RxInt modeIndex = 0.obs;
@ -22,12 +23,10 @@ class MediaController extends GetxController {
void setTypeIndex(int idx) { void setTypeIndex(int idx) {
typeIndex.value = idx; typeIndex.value = idx;
fetchInitial();
} }
void setModeIndex(int idx) { void setModeIndex(int idx) {
modeIndex.value = idx; modeIndex.value = idx;
fetchInitial();
} }
void setTag(String? newTag, {bool reload = true}) { void setTag(String? newTag, {bool reload = true}) {
@ -37,6 +36,10 @@ class MediaController extends GetxController {
} }
} }
void toggleRandom() {
random.value = random.value == 0 ? 1 : 0;
}
Future<List<Favorite>?> toggleFavorite( Future<List<Favorite>?> toggleFavorite(
MediaItem item, MediaItem item,
bool isFavorite, bool isFavorite,
@ -51,6 +54,7 @@ class MediaController extends GetxController {
Future<Feed?> _fetchItems({int? older, int? newer}) async { Future<Feed?> _fetchItems({int? older, int? newer}) async {
if (loading.value) return null; if (loading.value) return null;
loading.value = true; loading.value = true;
errorMessage.value = null;
try { try {
return await _api.fetchItems( return await _api.fetchItems(
older: older, older: older,
@ -61,11 +65,10 @@ class MediaController extends GetxController {
tag: tag.value, tag: tag.value,
); );
} catch (e) { } catch (e) {
Get.snackbar( final String errorText =
'Fehler beim Laden', 'Die Daten konnten nicht abgerufen werden. Wo Internet?';
'Die Daten konnten nicht abgerufen werden. Wo Internet?', errorMessage.value = errorText;
snackPosition: SnackPosition.BOTTOM, Get.snackbar('Fehler beim Laden', errorText);
);
return null; return null;
} finally { } finally {
loading.value = false; loading.value = false;
@ -73,7 +76,7 @@ class MediaController extends GetxController {
} }
Future<void> fetchInitial({int? id}) async { Future<void> fetchInitial({int? id}) async {
final result = await _fetchItems(older: id); final Feed? result = await _fetchItems(older: id);
if (result != null) { if (result != null) {
items.assignAll(result.items); items.assignAll(result.items);
atEnd.value = result.atEnd; atEnd.value = result.atEnd;
@ -83,7 +86,7 @@ class MediaController extends GetxController {
Future<void> fetchMore() async { Future<void> fetchMore() async {
if (items.isEmpty || atEnd.value) return; if (items.isEmpty || atEnd.value) return;
final result = await _fetchItems(older: items.last.id); final Feed? result = await _fetchItems(older: items.last.id);
if (result != null) { if (result != null) {
final Set<int> existingIds = items.map((e) => e.id).toSet(); final Set<int> existingIds = items.map((e) => e.id).toSet();
final List<MediaItem> newItems = result.items final List<MediaItem> newItems = result.items
@ -95,10 +98,9 @@ class MediaController extends GetxController {
} }
} }
Future<int> fetchNewer() async { Future<void> fetchNewer() async {
if (items.isEmpty || atStart.value) return 0; if (items.isEmpty || atStart.value) return;
final oldLength = items.length; final Feed? result = await _fetchItems(newer: items.first.id);
final result = await _fetchItems(newer: items.first.id);
if (result != null) { if (result != null) {
final Set<int> existingIds = items.map((e) => e.id).toSet(); final Set<int> existingIds = items.map((e) => e.id).toSet();
final List<MediaItem> newItems = result.items final List<MediaItem> newItems = result.items
@ -107,9 +109,8 @@ class MediaController extends GetxController {
items.insertAll(0, newItems); items.insertAll(0, newItems);
items.refresh(); items.refresh();
atStart.value = result.atStart; atStart.value = result.atStart;
return items.length - oldLength;
} }
return 0; return;
} }
Future<void> handleRefresh() async { Future<void> handleRefresh() async {
@ -122,15 +123,11 @@ class MediaController extends GetxController {
} }
Future<void> handleLoading() async { Future<void> handleLoading() async {
if (loading.value) return;
if (!loading.value && !atEnd.value) { if (!loading.value && !atEnd.value) {
await fetchMore(); await fetchMore();
} }
} }
void toggleRandom() {
random.value = random.value == 1 ? 0 : 1;
fetchInitial();
}
bool get isRandomEnabled => random.value == 1; bool get isRandomEnabled => random.value == 1;
} }

View File

@ -19,9 +19,6 @@ class SettingsController extends GetxController {
RxBool drawerSwipeEnabled = true.obs; RxBool drawerSwipeEnabled = true.obs;
RxInt crossAxisCount = 0.obs; RxInt crossAxisCount = 0.obs;
RxInt videoControlsTimerNotifier = 0.obs;
RxInt hideControlsNotifier = 0.obs;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
@ -53,9 +50,6 @@ class SettingsController extends GetxController {
await saveSettings(); await saveSettings();
} }
void resetVideoControlsTimer() => videoControlsTimerNotifier.value++;
void hideVideoControls() => hideControlsNotifier.value++;
Future<void> loadSettings() async { Future<void> loadSettings() async {
muted.value = await storage.getBoolean(_StorageKeys.muted) ?? false; muted.value = await storage.getBoolean(_StorageKeys.muted) ?? false;
crossAxisCount.value = crossAxisCount.value =

View File

@ -8,14 +8,21 @@ import 'package:f0ckapp/widgets/video_widget.dart';
class FullScreenMediaView extends StatefulWidget { class FullScreenMediaView extends StatefulWidget {
final MediaItem item; final MediaItem item;
final Duration? initialPosition;
const FullScreenMediaView({super.key, required this.item}); const FullScreenMediaView({
super.key,
required this.item,
this.initialPosition,
});
@override @override
State createState() => _FullScreenMediaViewState(); State createState() => _FullScreenMediaViewState();
} }
class _FullScreenMediaViewState extends State<FullScreenMediaView> { class _FullScreenMediaViewState extends State<FullScreenMediaView> {
final GlobalKey<VideoWidgetState> _videoKey = GlobalKey<VideoWidgetState>();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -30,44 +37,59 @@ class _FullScreenMediaViewState extends State<FullScreenMediaView> {
super.dispose(); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return PopScope(
backgroundColor: Colors.black, onPopInvokedWithResult: (bool didPop, Object? result) async {
body: Stack( return _popWithPosition();
children: [ },
Positioned.fill( child: Scaffold(
child: widget.item.mime.startsWith('image') backgroundColor: Colors.black,
? InteractiveViewer( body: Stack(
minScale: 1.0, children: [
maxScale: 7.0, Positioned.fill(
child: CachedNetworkImage( child: widget.item.mime.startsWith('image')
imageUrl: widget.item.mediaUrl, ? InteractiveViewer(
fit: BoxFit.contain, minScale: 1.0,
placeholder: (context, url) => maxScale: 7.0,
const Center(child: CircularProgressIndicator()), child: CachedNetworkImage(
errorWidget: (context, url, error) => imageUrl: widget.item.mediaUrl,
const Icon(Icons.error), 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,
),
), ),
) ),
: Center( SafeArea(
child: VideoWidget( child: Align(
details: widget.item, alignment: Alignment.topLeft,
isActive: true, child: IconButton(
fullScreen: true, icon: const Icon(Icons.arrow_back, color: Colors.white),
), onPressed: _popWithPosition,
), ),
),
SafeArea(
child: Align(
alignment: Alignment.topLeft,
child: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
), ),
), ),
), ],
], ),
), ),
); );
} }

View File

@ -7,6 +7,7 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pullex/pullex.dart'; import 'package:pullex/pullex.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:f0ckapp/services/api.dart'; import 'package:f0ckapp/services/api.dart';
import 'package:f0ckapp/widgets/tagfooter.dart'; import 'package:f0ckapp/widgets/tagfooter.dart';
@ -39,10 +40,12 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
final RxInt _currentIndex = 0.obs; final RxInt _currentIndex = 0.obs;
final MethodChannel _mediaSaverChannel = const MethodChannel('MediaShit'); final MethodChannel _mediaSaverChannel = const MethodChannel('MediaShit');
final Map<int, PullexRefreshController> _refreshControllers = {}; final Map<int, PullexRefreshController> _refreshControllers = {};
final Map<int, GlobalKey<VideoWidgetState>> _videoWidgetKeys = {};
bool _isLoading = true; bool _isLoading = true;
bool _itemNotFound = false; bool _itemNotFound = false;
final Set<int> _readyItemIds = {}; final RxSet<int> _readyItemIds = <int>{}.obs;
final Rxn<int> _animatingFavoriteId = Rxn<int>();
final List<PopupMenuEntry<ShareAction>> _shareMenuItems = const [ final List<PopupMenuEntry<ShareAction>> _shareMenuItems = const [
PopupMenuItem( PopupMenuItem(
@ -65,6 +68,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
timeago.setLocaleMessages('de', timeago.DeMessages());
_loadInitialItem(); _loadInitialItem();
} }
@ -137,9 +141,21 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
_currentIndex.value = idx; _currentIndex.value = idx;
final MediaItem item = mediaController.items[idx]; final MediaItem item = mediaController.items[idx];
if (item.mime.startsWith('image/') && !_readyItemIds.contains(item.id)) { if (item.mime.startsWith('image/') && !_readyItemIds.contains(item.id)) {
setState(() => _readyItemIds.add(item.id)); _readyItemIds.add(item.id);
} }
} }
if (idx + 1 < mediaController.items.length) {
DefaultCacheManager().downloadFile(
mediaController.items[idx + 1].mediaUrl,
);
}
if (idx - 1 >= 0) {
DefaultCacheManager().downloadFile(
mediaController.items[idx - 1].mediaUrl,
);
}
if (idx >= mediaController.items.length - 2 && if (idx >= mediaController.items.length - 2 &&
!mediaController.loading.value && !mediaController.loading.value &&
!mediaController.atEnd.value) { !mediaController.atEnd.value) {
@ -201,6 +217,37 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
} }
} }
Future<void> _handleFullScreen(MediaItem currentItem) async {
if (currentItem.mime.startsWith('image')) {
Get.to(
() => FullScreenMediaView(item: currentItem),
fullscreenDialog: true,
);
return;
}
final GlobalKey<VideoWidgetState>? key = _videoWidgetKeys[currentItem.id];
final VideoWidgetState? videoState = key?.currentState;
if (videoState == null || !videoState.videoController.value.isInitialized) {
return;
}
final Duration position = videoState.videoController.value.position;
await videoState.videoController.pause();
final Duration? newPosition = await Get.to<Duration?>(
() => FullScreenMediaView(item: currentItem, initialPosition: position),
fullscreenDialog: true,
);
if (mounted && videoState.mounted) {
if (newPosition != null) {
await videoState.videoController.seekTo(newPosition);
}
await videoState.videoController.play();
}
}
@override @override
void dispose() { void dispose() {
_pageController?.dispose(); _pageController?.dispose();
@ -210,197 +257,270 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
super.dispose(); super.dispose();
} }
Future<void> _handleFavoriteToggle(MediaItem item, bool isFavorite) async {
if (!authController.isLoggedIn) return;
HapticFeedback.lightImpact();
final List<Favorite>? newFavorites = await mediaController.toggleFavorite(
item,
isFavorite,
);
final int index = mediaController.items.indexWhere((i) => i.id == item.id);
if (newFavorites != null && index != -1) {
mediaController.items[index] = item.copyWith(favorites: newFavorites);
mediaController.items.refresh();
}
_animatingFavoriteId.value = item.id;
Future.delayed(const Duration(milliseconds: 700), () {
if (_animatingFavoriteId.value == item.id) {
_animatingFavoriteId.value = null;
}
});
}
Widget _buildMedia(MediaItem item, bool isActive) { Widget _buildMedia(MediaItem item, bool isActive) {
Widget mediaWidget;
final bool isFavorite =
item.favorites?.any((f) => f.userId == authController.user.value?.id) ??
false;
if (item.mime.startsWith('image/')) { if (item.mime.startsWith('image/')) {
return CachedNetworkImage( mediaWidget = CachedNetworkImage(
imageUrl: item.mediaUrl, imageUrl: item.mediaUrl,
fit: BoxFit.contain, fit: BoxFit.contain,
placeholder: (context, url) =>
const Center(child: CircularProgressIndicator()),
errorWidget: (c, e, s) => const Icon(Icons.broken_image, size: 100), errorWidget: (c, e, s) => const Icon(Icons.broken_image, size: 100),
); );
} else if (item.mime.startsWith('video/') || } else if (item.mime.startsWith('video/') ||
item.mime.startsWith('audio/')) { item.mime.startsWith('audio/')) {
return VideoWidget( final GlobalKey<VideoWidgetState> key = _videoWidgetKeys.putIfAbsent(
item.id,
() => GlobalKey<VideoWidgetState>(),
);
mediaWidget = VideoWidget(
key: key,
details: item, details: item,
isActive: isActive, isActive: isActive,
onInitialized: () { onInitialized: () {
if (mounted && !_readyItemIds.contains(item.id)) { if (mounted && !_readyItemIds.contains(item.id)) {
setState(() => _readyItemIds.add(item.id)); _readyItemIds.add(item.id);
} }
}, },
); );
} else { } else {
return const Icon(Icons.help_outline, size: 100); mediaWidget = const Icon(Icons.help_outline, size: 100);
} }
return Hero(
tag: 'media_${item.id}',
child: Stack(
alignment: Alignment.center,
children: [
GestureDetector(
onDoubleTap: () => _handleFavoriteToggle(item, isFavorite),
child: mediaWidget,
),
Obx(() {
final showAnimation = _animatingFavoriteId.value == item.id;
return AnimatedOpacity(
opacity: showAnimation ? 1.0 : 0.0,
duration: const Duration(milliseconds: 200),
child: AnimatedScale(
scale: showAnimation ? 1.0 : 0.5,
duration: const Duration(milliseconds: 400),
curve: Curves.easeOutBack,
child: Icon(
isFavorite ? Icons.favorite : Icons.favorite_outline,
color: Colors.red,
size: 100,
),
),
);
}),
],
),
);
}
PreferredSizeWidget _buildAppBar(BuildContext context) {
return AppBar(
title: Obx(() {
if (_isLoading) {
return Text('Lade f0ck #${widget.initialId}...');
}
if (_itemNotFound ||
mediaController.items.isEmpty ||
_currentIndex.value >= mediaController.items.length) {
return const Text('Fehler');
}
final MediaItem currentItem =
mediaController.items[_currentIndex.value];
return Text('f0ck #${currentItem.id}');
}),
actions: [
Obx(() {
final bool showActions =
!_isLoading &&
!_itemNotFound &&
mediaController.items.isNotEmpty &&
_currentIndex.value < mediaController.items.length;
if (!showActions) {
return const SizedBox.shrink();
}
final MediaItem currentItem =
mediaController.items[_currentIndex.value];
return Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.fullscreen),
onPressed: () => _handleFullScreen(currentItem),
),
IconButton(
icon: const Icon(Icons.download),
onPressed: () async => await _downloadMedia(currentItem),
),
PopupMenuButton<ShareAction>(
onSelected: (value) => _handleShareAction(value, currentItem),
itemBuilder: (context) => _shareMenuItems,
icon: const Icon(Icons.share),
),
],
);
}),
Builder(
builder: (context) => IconButton(
icon: const Icon(Icons.menu),
onPressed: () => Scaffold.of(context).openEndDrawer(),
),
),
],
);
}
Widget _buildBody(BuildContext context) {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (_itemNotFound) {
return const Center(child: Text('f0ck nicht gefunden.'));
}
return Obx(() {
if (mediaController.items.isEmpty) {
return const Center(child: Text('Keine Items zum Anzeigen.'));
}
return PageView.builder(
controller: _pageController!,
itemCount: mediaController.items.length,
onPageChanged: _onPageChanged,
itemBuilder: (context, index) {
if (index >= mediaController.items.length) {
return const SizedBox.shrink();
}
final MediaItem item = mediaController.items[index];
final PullexRefreshController refreshController = _refreshControllers
.putIfAbsent(item.id, () => PullexRefreshController());
return Obx(() {
final bool isReady = _readyItemIds.contains(item.id);
return PullexRefresh(
onRefresh: () => _onRefresh(item.id, refreshController),
header: const WaterDropHeader(),
controller: refreshController,
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: AnimatedBuilder(
animation: _pageController!,
builder: (context, child) {
return buildAnimatedTransition(
context: context,
pageController: _pageController!,
index: index,
child: child!,
);
},
child: Obx(
() => _buildMedia(item, index == _currentIndex.value),
),
),
),
if (isReady)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TagSection(tags: item.tags ?? []),
Obx(() {
if (!authController.isLoggedIn) {
return const SizedBox.shrink();
}
final TextStyle? infoTextStyle = Theme.of(
context,
).textTheme.bodySmall;
return Padding(
padding: const EdgeInsets.only(top: 24.0),
child: Column(
children: [
FavoriteSection(item: item, index: index),
const SizedBox(height: 16),
Text(
"Dateigröße: ${(item.size / 1024).toStringAsFixed(1)} KB",
style: infoTextStyle,
),
Text(
"Typ: ${item.mime}",
style: infoTextStyle,
),
Text(
"ID: ${item.id}",
style: infoTextStyle,
),
Text(
"Hochgeladen: ${timeago.format(DateTime.fromMillisecondsSinceEpoch(item.stamp * 1000), locale: 'de')}",
style: infoTextStyle,
),
],
),
);
}),
],
),
),
),
const SliverToBoxAdapter(
child: SafeArea(child: SizedBox.shrink()),
),
],
),
);
});
},
);
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_isLoading) { return Scaffold(
return Scaffold( endDrawer: const EndDrawer(),
appBar: AppBar(title: Text('Lade f0ck #${widget.initialId}...')), endDrawerEnableOpenDragGesture:
body: const Center(child: CircularProgressIndicator()), settingsController.drawerSwipeEnabled.value,
); appBar: _buildAppBar(context),
} body: _buildBody(context),
persistentFooterButtons: mediaController.tag.value != null
if (_itemNotFound) { ? [TagFooter()]
return Scaffold( : null,
appBar: AppBar(title: const Text('Fehler')), );
body: const Center(child: Text('f0ck nicht gefunden.')),
);
}
return Obx(() {
if (mediaController.items.isEmpty ||
_currentIndex.value >= mediaController.items.length) {
return Scaffold(
appBar: AppBar(title: const Text('Fehler')),
body: const Center(child: Text('Keine Items zum Anzeigen.')),
);
}
final MediaItem currentItem = mediaController.items[_currentIndex.value];
return Scaffold(
endDrawer: const EndDrawer(),
endDrawerEnableOpenDragGesture:
settingsController.drawerSwipeEnabled.value,
appBar: AppBar(
title: Text('f0ck #${currentItem.id}'),
actions: [
IconButton(
icon: const Icon(Icons.fullscreen),
onPressed: () {
Get.to(
FullScreenMediaView(item: currentItem),
fullscreenDialog: true,
);
},
),
IconButton(
icon: const Icon(Icons.download),
onPressed: () async => await _downloadMedia(currentItem),
),
PopupMenuButton<ShareAction>(
onSelected: (value) => _handleShareAction(value, currentItem),
itemBuilder: (context) => _shareMenuItems,
icon: const Icon(Icons.share),
),
Builder(
builder: (context) => IconButton(
icon: const Icon(Icons.menu),
onPressed: () => Scaffold.of(context).openEndDrawer(),
),
),
],
),
body: PageView.builder(
controller: _pageController!,
itemCount: mediaController.items.length,
onPageChanged: _onPageChanged,
itemBuilder: (context, index) {
final MediaItem item = mediaController.items[index];
final bool isReady = _readyItemIds.contains(item.id);
final ScrollController scrollController = ScrollController();
final PullexRefreshController refreshController =
_refreshControllers.putIfAbsent(
item.id,
() => PullexRefreshController(),
);
return Stack(
children: [
PullexRefresh(
onRefresh: () => _onRefresh(item.id, refreshController),
header: const WaterDropHeader(),
controller: refreshController,
child: CustomScrollView(
controller: scrollController,
slivers: [
SliverToBoxAdapter(
child: AnimatedBuilder(
animation: _pageController!,
builder: (context, child) {
return buildAnimatedTransition(
context: context,
pageController: _pageController!,
index: index,
child: child!,
);
},
child: Obx(
() =>
_buildMedia(item, index == _currentIndex.value),
),
),
),
if (isReady)
SliverFillRemaining(
hasScrollBody: false,
fillOverscroll: true,
child: GestureDetector(
onTap: () => settingsController.hideVideoControls(),
behavior: HitTestBehavior.translucent,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [TagSection(tags: item.tags ?? [])],
),
),
),
),
const SliverToBoxAdapter(
child: SafeArea(child: SizedBox.shrink()),
),
],
),
),
Obx(() {
if (!authController.isLoggedIn) {
return const SizedBox.shrink();
}
final MediaItem currentItem =
mediaController.items[_currentIndex.value];
return DraggableScrollableSheet(
initialChildSize: 0.11,
minChildSize: 0.11,
maxChildSize: 0.245,
snap: true,
builder: (context, scrollController) => ListView(
controller: scrollController,
padding: const EdgeInsets.only(left: 16, right: 16),
children: [
FavoriteSection(
item: currentItem,
index: _currentIndex.value,
),
const SizedBox(height: 16),
Text(
"Dateigröße: ${(currentItem.size / 1024).toStringAsFixed(1)} KB",
style: Theme.of(context).textTheme.bodySmall,
),
Text(
"Typ: ${currentItem.mime}",
style: Theme.of(context).textTheme.bodySmall,
),
Text(
"ID: ${currentItem.id}",
style: Theme.of(context).textTheme.bodySmall,
),
Text(
"Hochgeladen am: ${DateTime.fromMillisecondsSinceEpoch(currentItem.stamp * 1000)}",
style: Theme.of(context).textTheme.bodySmall,
),
],
),
);
}),
],
);
},
),
persistentFooterButtons: mediaController.tag.value != null
? [TagFooter()]
: null,
);
});
} }
} }

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pullex/pullex.dart'; import 'package:pullex/pullex.dart';
import 'package:f0ckapp/models/item.dart';
import 'package:f0ckapp/widgets/tagfooter.dart'; import 'package:f0ckapp/widgets/tagfooter.dart';
import 'package:f0ckapp/utils/customsearchdelegate.dart'; import 'package:f0ckapp/utils/customsearchdelegate.dart';
import 'package:f0ckapp/widgets/end_drawer.dart'; import 'package:f0ckapp/widgets/end_drawer.dart';
@ -28,11 +29,27 @@ class _MediaGrid extends State<MediaGrid> {
late final _MediaGridAppBar _appBar; late final _MediaGridAppBar _appBar;
late final _MediaGridBody _body; late final _MediaGridBody _body;
Worker? _filterWorker;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_mediaController.fetchInitial(); _mediaController.fetchInitial();
_filterWorker = everAll(
[
_mediaController.typeIndex,
_mediaController.modeIndex,
_mediaController.tag,
_mediaController.random,
],
(_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_refreshController.requestRefresh();
});
},
);
_appBar = _MediaGridAppBar(mediaController: _mediaController); _appBar = _MediaGridAppBar(mediaController: _mediaController);
_body = _MediaGridBody( _body = _MediaGridBody(
refreshController: _refreshController, refreshController: _refreshController,
@ -44,6 +61,7 @@ class _MediaGrid extends State<MediaGrid> {
@override @override
void dispose() { void dispose() {
_filterWorker?.dispose();
_scrollController.dispose(); _scrollController.dispose();
_refreshController.dispose(); _refreshController.dispose();
super.dispose(); super.dispose();
@ -51,19 +69,55 @@ class _MediaGrid extends State<MediaGrid> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Obx( return Obx(() {
() => Scaffold( if (_mediaController.loading.value && _mediaController.items.isEmpty) {
return Scaffold(
appBar: _appBar,
body: const Center(child: CircularProgressIndicator()),
);
}
if (_mediaController.errorMessage.value != null &&
_mediaController.items.isEmpty) {
return Scaffold(
appBar: _appBar,
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, color: Colors.red, size: 60),
const SizedBox(height: 16),
Text(
'${_mediaController.errorMessage.value}',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _mediaController.fetchInitial(),
child: const Text('Erneut versuchen'),
),
],
),
),
),
);
}
return Scaffold(
endDrawer: const EndDrawer(), endDrawer: const EndDrawer(),
endDrawerEnableOpenDragGesture: endDrawerEnableOpenDragGesture:
_settingsController.drawerSwipeEnabled.value, _settingsController.drawerSwipeEnabled.value,
bottomNavigationBar: FilterBar(scrollController: _scrollController), bottomNavigationBar: FilterBar(),
appBar: _appBar, appBar: _appBar,
body: _body, body: _body,
persistentFooterButtons: _mediaController.tag.value != null persistentFooterButtons: _mediaController.tag.value != null
? [TagFooter()] ? [TagFooter()]
: null, : null,
), );
); });
} }
} }
@ -77,7 +131,9 @@ class _MediaGridAppBar extends StatelessWidget implements PreferredSizeWidget {
return AppBar( return AppBar(
title: InkWell( title: InkWell(
onTap: () { onTap: () {
mediaController.setTag(null); if (mediaController.tag.value != null) {
mediaController.setTag(null);
}
}, },
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -105,7 +161,9 @@ class _MediaGridAppBar extends StatelessWidget implements PreferredSizeWidget {
? Icons.shuffle_on_outlined ? Icons.shuffle_on_outlined
: Icons.shuffle, : Icons.shuffle,
), ),
onPressed: mediaController.toggleRandom, onPressed: () {
mediaController.toggleRandom();
},
), ),
), ),
IconButton( IconButton(
@ -133,57 +191,72 @@ class _MediaGridBody extends StatelessWidget {
final SettingsController settingsController; final SettingsController settingsController;
final ScrollController scrollController; final ScrollController scrollController;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return PullexRefresh( if (mediaController.items.isEmpty && !mediaController.loading.value) {
controller: refreshController, return const Center(
enablePullDown: true, child: Text(
enablePullUp: true, 'Keine f0cks gefunden.\n\nVersuch mal andere Filter.',
header: const WaterDropHeader(), textAlign: TextAlign.center,
onRefresh: () async { ),
try { );
await mediaController.handleRefresh(); }
} finally { return NotificationListener<ScrollNotification>(
refreshController.refreshCompleted(); onNotification: (scrollInfo) {
if (!mediaController.loading.value &&
!mediaController.atEnd.value &&
scrollInfo.metrics.pixels >=
scrollInfo.metrics.maxScrollExtent - 600) {
mediaController.handleLoading();
} }
return true;
}, },
onLoading: () async { child: PullexRefresh(
try { controller: refreshController,
await mediaController.handleLoading(); onRefresh: () async {
} finally { try {
refreshController.loadComplete(); await mediaController.handleRefresh();
} } finally {
}, refreshController.refreshCompleted();
child: Obx( }
() => GridView.builder( },
addAutomaticKeepAlives: false, header: const WaterDropHeader(),
controller: scrollController, child: Obx(
physics: const NeverScrollableScrollPhysics(), () => GridView.builder(
shrinkWrap: true, addAutomaticKeepAlives: false,
padding: const EdgeInsets.all(4), controller: scrollController,
itemCount: mediaController.items.length, shrinkWrap: true,
gridDelegate: settingsController.crossAxisCount.value == 0 physics: const NeverScrollableScrollPhysics(),
? const SliverGridDelegateWithMaxCrossAxisExtent( padding: const EdgeInsets.all(4),
maxCrossAxisExtent: 150, itemCount: mediaController.items.length,
crossAxisSpacing: 5, gridDelegate: settingsController.crossAxisCount.value == 0
mainAxisSpacing: 5, ? const SliverGridDelegateWithMaxCrossAxisExtent(
childAspectRatio: 1, maxCrossAxisExtent: 150,
) crossAxisSpacing: 5,
: SliverGridDelegateWithFixedCrossAxisCount( mainAxisSpacing: 5,
crossAxisCount: settingsController.crossAxisCount.value, childAspectRatio: 1,
crossAxisSpacing: 5, )
mainAxisSpacing: 5, : SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 1, crossAxisCount: settingsController.crossAxisCount.value,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: 1,
),
itemBuilder: (context, index) {
final MediaItem item = mediaController.items[index];
return Hero(
tag: 'media_${item.id}',
child: Material(
type: MaterialType.transparency,
child: GestureDetector(
key: ValueKey(item.id),
onTap: () => Get.toNamed('/${item.id}'),
child: MediaTile(item: item),
),
), ),
itemBuilder: (context, index) { );
final item = mediaController.items[index]; },
return GestureDetector( ),
key: ValueKey(item.id),
onTap: () => Get.toNamed('/${item.id}'),
child: MediaTile(item: item),
);
},
), ),
), ),
); );

View File

@ -5,9 +5,7 @@ import 'package:get/get.dart';
import 'package:f0ckapp/controller/mediacontroller.dart'; import 'package:f0ckapp/controller/mediacontroller.dart';
class FilterBar extends StatelessWidget { class FilterBar extends StatelessWidget {
final ScrollController scrollController; const FilterBar({super.key});
const FilterBar({super.key, required this.scrollController});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -32,7 +30,6 @@ class FilterBar extends StatelessWidget {
onChanged: (String? newValue) { onChanged: (String? newValue) {
if (newValue != null) { if (newValue != null) {
c.setTypeIndex(mediaTypes.indexOf(newValue)); c.setTypeIndex(mediaTypes.indexOf(newValue));
scrollController.jumpTo(0);
} }
}, },
), ),
@ -51,7 +48,6 @@ class FilterBar extends StatelessWidget {
onChanged: (String? newValue) { onChanged: (String? newValue) {
if (newValue != null) { if (newValue != null) {
c.setModeIndex(mediaModes.indexOf(newValue)); c.setModeIndex(mediaModes.indexOf(newValue));
scrollController.jumpTo(0);
} }
}, },
), ),

View File

@ -3,19 +3,16 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_video_player_plus/cached_video_player_plus.dart'; import 'package:cached_video_player_plus/cached_video_player_plus.dart';
import 'package:get/get.dart';
import 'package:f0ckapp/controller/settingscontroller.dart';
class VideoControlsOverlay extends StatefulWidget { class VideoControlsOverlay extends StatefulWidget {
final CachedVideoPlayerPlusController controller; final CachedVideoPlayerPlusController controller;
final VoidCallback onOverlayTap;
final bool muted;
final VoidCallback onMuteToggle;
const VideoControlsOverlay({ const VideoControlsOverlay({
super.key, super.key,
required this.controller, required this.controller,
required this.onOverlayTap,
required this.muted,
required this.onMuteToggle,
}); });
@override @override
@ -23,175 +20,98 @@ class VideoControlsOverlay extends StatefulWidget {
} }
class _VideoControlsOverlayState extends State<VideoControlsOverlay> { class _VideoControlsOverlayState extends State<VideoControlsOverlay> {
bool _showSeekIndicator = false; final SettingsController _settingsController = Get.find();
bool _isRewinding = false;
Timer? _hideTimer; Timer? _hideTimer;
bool _controlsVisible = false;
bool _isScrubbing = false;
Duration _scrubbingStartPosition = Duration.zero;
double _scrubbingStartDx = 0.0;
Duration _scrubbingSeekPosition = Duration.zero;
@override
void initState() {
super.initState();
widget.controller.addListener(_listener);
}
@override @override
void dispose() { void dispose() {
_hideTimer?.cancel(); _hideTimer?.cancel();
widget.controller.removeListener(_listener);
super.dispose(); super.dispose();
} }
void _handleDoubleTap(TapDownDetails details) { void _listener() {
final double screenWidth = MediaQuery.of(context).size.width; if (mounted) {
final bool isRewind = details.globalPosition.dx < screenWidth / 2; setState(() {});
widget.onOverlayTap(); }
}
Future(() {
if (isRewind) {
final Duration newPosition =
widget.controller.value.position - const Duration(seconds: 10);
widget.controller.seekTo(
newPosition < Duration.zero ? Duration.zero : newPosition,
);
} else {
final Duration newPosition =
widget.controller.value.position + const Duration(seconds: 10);
final Duration duration = widget.controller.value.duration;
widget.controller.seekTo(
newPosition > duration ? duration : newPosition,
);
}
});
void _startHideTimer() {
_hideTimer?.cancel(); _hideTimer?.cancel();
setState(() { _hideTimer = Timer(const Duration(seconds: 5), () {
_showSeekIndicator = true; if (mounted) {
_isRewinding = isRewind; setState(() => _controlsVisible = false);
}); }
_hideTimer = Timer(const Duration(milliseconds: 500), () {
setState(() => _showSeekIndicator = false);
}); });
} }
@override void _toggleControlsVisibility() {
Widget build(BuildContext context) { setState(() => _controlsVisible = !_controlsVisible);
return Stack( if (_controlsVisible) {
alignment: Alignment.center, _startHideTimer();
children: [ }
GestureDetector( }
onTap: widget.onOverlayTap,
onDoubleTapDown: _handleDoubleTap, void _handlePlayPause() {
child: Container(color: Colors.transparent), widget.controller.value.isPlaying
), ? widget.controller.pause()
AnimatedOpacity( : widget.controller.play();
opacity: _showSeekIndicator ? 1.0 : 0.0, _startHideTimer();
duration: const Duration(milliseconds: 200), }
child: Align(
alignment: _isRewinding void _onHorizontalDragStart(DragStartDetails details) {
? Alignment.centerLeft if (!widget.controller.value.isInitialized || !_controlsVisible) return;
: Alignment.centerRight,
child: Padding( setState(() {
padding: const EdgeInsets.symmetric(horizontal: 40.0), _isScrubbing = true;
child: Icon( _scrubbingStartPosition = widget.controller.value.position;
_isRewinding _scrubbingStartDx = details.globalPosition.dx;
? Icons.fast_rewind_rounded _scrubbingSeekPosition = widget.controller.value.position;
: Icons.fast_forward_rounded, });
color: Colors.white70, _hideTimer?.cancel();
size: 60, }
),
), void _onHorizontalDragUpdate(DragUpdateDetails details) {
), if (!_isScrubbing) return;
),
IconButton( final double delta = details.globalPosition.dx - _scrubbingStartDx;
icon: Icon( final int seekMillis =
widget.controller.value.isPlaying ? Icons.pause : Icons.play_arrow, _scrubbingStartPosition.inMilliseconds + (delta * 300).toInt();
size: 64,
), setState(() {
onPressed: () { final Duration duration = widget.controller.value.duration;
widget.onOverlayTap(); final Duration seekDuration = Duration(milliseconds: seekMillis);
widget.controller.value.isPlaying final Duration clampedSeekDuration = seekDuration < Duration.zero
? widget.controller.pause() ? Duration.zero
: widget.controller.play(); : (seekDuration > duration ? duration : seekDuration);
}, _scrubbingSeekPosition = clampedSeekDuration;
), });
Positioned( }
right: 12,
bottom: 12, void _onHorizontalDragEnd(DragEndDetails details) {
child: IconButton( if (!_isScrubbing) return;
icon: Icon(
widget.muted ? Icons.volume_off : Icons.volume_up, widget.controller.seekTo(_scrubbingSeekPosition);
size: 16, setState(() => _isScrubbing = false);
), _startHideTimer();
onPressed: () { }
widget.onOverlayTap();
widget.onMuteToggle(); void _onHorizontalDragCancel() {
}, if (!_isScrubbing) return;
), setState(() => _isScrubbing = false);
), _startHideTimer();
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 0),
child: LayoutBuilder(
builder: (context, constraints) {
return Stack(
clipBehavior: Clip.none,
children: [
Positioned(
left: 10,
bottom: 12,
child: Text(
'${_formatDuration(widget.controller.value.position)} / ${_formatDuration(widget.controller.value.duration)}',
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
Listener(
onPointerDown: (_) {
widget.onOverlayTap();
},
child: VideoProgressIndicator(
widget.controller,
allowScrubbing: true,
padding: const EdgeInsets.only(top: 25.0),
colors: VideoProgressColors(
playedColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(
context,
).colorScheme.surface.withValues(alpha: 0.5),
bufferedColor: Theme.of(
context,
).colorScheme.secondary.withValues(alpha: 0.5),
),
),
),
if (widget.controller.value.duration.inMilliseconds > 0)
Positioned(
left:
(widget.controller.value.position.inMilliseconds /
widget
.controller
.value
.duration
.inMilliseconds) *
constraints.maxWidth -
6,
bottom: -4,
child: Container(
width: 12,
height: 12,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
border: Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2,
),
),
),
),
],
);
},
),
),
),
],
);
} }
String _formatDuration(Duration? duration) { String _formatDuration(Duration? duration) {
@ -199,4 +119,143 @@ class _VideoControlsOverlayState extends State<VideoControlsOverlay> {
String twoDigits(int n) => n.toString().padLeft(2, '0'); String twoDigits(int n) => n.toString().padLeft(2, '0');
return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}"; return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}";
} }
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(
child: GestureDetector(
onTap: _toggleControlsVisibility,
onHorizontalDragStart: _controlsVisible ? _onHorizontalDragStart : null,
onHorizontalDragUpdate: _controlsVisible ? _onHorizontalDragUpdate : null,
onHorizontalDragEnd: _controlsVisible ? _onHorizontalDragEnd : null,
onHorizontalDragCancel: _controlsVisible ? _onHorizontalDragCancel : null,
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
color: _controlsVisible && !_isScrubbing
? Colors.black.withValues(alpha: 0.5)
: Colors.transparent,
),
),
),
AnimatedOpacity(
opacity: _isScrubbing ? 1.0 : 0.0,
duration: const Duration(milliseconds: 200),
child: _buildScrubbingIndicator(),
),
AnimatedOpacity(
opacity: _controlsVisible && !_isScrubbing ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: Align(
alignment: Alignment.bottomCenter,
child: _buildBottomBar(),
),
),
],
);
}
Widget _buildScrubbingIndicator() {
final Duration positionChange =
_scrubbingSeekPosition - _scrubbingStartPosition;
final String changeSign = positionChange.isNegative ? '-' : '+';
final String changeText = _formatDuration(positionChange.abs());
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.7),
borderRadius: BorderRadius.circular(8),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_formatDuration(_scrubbingSeekPosition),
style: const TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
'[$changeSign$changeText]',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.8),
fontSize: 16,
),
),
],
),
);
}
Widget _buildBottomBar() {
return Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 5),
child: Row(
children: [
IconButton(
icon: Icon(
widget.controller.value.isPlaying
? Icons.pause
: Icons.play_arrow,
color: Theme.of(context).colorScheme.primary,
size: 24,
),
onPressed: _handlePlayPause,
constraints: const BoxConstraints(),
padding: EdgeInsets.zero,
),
Text(
_formatDuration(widget.controller.value.position),
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: 12,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: VideoProgressIndicator(
widget.controller,
allowScrubbing: true,
colors: VideoProgressColors(
playedColor: Theme.of(context).colorScheme.primary,
backgroundColor: Colors.white.withValues(alpha: 0.3),
bufferedColor: Colors.white.withValues(alpha: 0.6),
),
),
),
),
Text(
_formatDuration(widget.controller.value.duration),
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: 12,
),
),
const SizedBox(width: 8),
Obx(
() => IconButton(
icon: Icon(
_settingsController.muted.value
? Icons.volume_off
: Icons.volume_up,
color: Theme.of(context).colorScheme.primary,
size: 24,
),
onPressed: () {
_settingsController.toggleMuted();
_startHideTimer();
},
constraints: const BoxConstraints(),
padding: EdgeInsets.zero,
),
),
],
),
);
}
} }

View File

@ -16,6 +16,7 @@ class VideoWidget extends StatefulWidget {
final bool isActive; final bool isActive;
final bool fullScreen; final bool fullScreen;
final VoidCallback? onInitialized; final VoidCallback? onInitialized;
final Duration? initialPosition;
const VideoWidget({ const VideoWidget({
super.key, super.key,
@ -23,21 +24,18 @@ class VideoWidget extends StatefulWidget {
required this.isActive, required this.isActive,
this.fullScreen = false, this.fullScreen = false,
this.onInitialized, this.onInitialized,
this.initialPosition,
}); });
@override @override
State<VideoWidget> createState() => _VideoWidgetState(); State<VideoWidget> createState() => VideoWidgetState();
} }
class _VideoWidgetState extends State<VideoWidget> { class VideoWidgetState extends State<VideoWidget> {
final MediaController mediaController = Get.find<MediaController>(); final MediaController mediaController = Get.find<MediaController>();
final SettingsController settingsController = Get.find<SettingsController>(); final SettingsController settingsController = Get.find<SettingsController>();
late CachedVideoPlayerPlusController videoController; late CachedVideoPlayerPlusController videoController;
late Worker _muteWorker; late Worker _muteWorker;
late Worker _timerResetWorker;
late Worker _hideControlsWorker;
bool _showControls = false;
Timer? _hideControlsTimer;
@override @override
void initState() { void initState() {
@ -48,22 +46,6 @@ class _VideoWidgetState extends State<VideoWidget> {
videoController.setVolume(muted ? 0.0 : 1.0); videoController.setVolume(muted ? 0.0 : 1.0);
} }
}); });
_timerResetWorker = ever(settingsController.videoControlsTimerNotifier, (
_,
) {
if (widget.isActive && mounted) {
if (!_showControls) {
setState(() => _showControls = true);
}
_startHideControlsTimer();
}
});
_hideControlsWorker = ever(settingsController.hideControlsNotifier, (_) {
if (mounted && _showControls) {
setState(() => _showControls = false);
_hideControlsTimer?.cancel();
}
});
} }
Future<void> _initController() async { Future<void> _initController() async {
@ -72,8 +54,14 @@ class _VideoWidgetState extends State<VideoWidget> {
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true), videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
); );
await videoController.initialize(); await videoController.initialize();
widget.onInitialized?.call();
if (!mounted) return; if (!mounted) return;
setState(() {});
if (widget.initialPosition != null) {
await videoController.seekTo(widget.initialPosition!);
}
widget.onInitialized?.call();
videoController.setLooping(true); videoController.setLooping(true);
videoController.setVolume(settingsController.muted.value ? 0.0 : 1.0); videoController.setVolume(settingsController.muted.value ? 0.0 : 1.0);
@ -93,10 +81,12 @@ class _VideoWidgetState extends State<VideoWidget> {
} }
if (widget.isActive != oldWidget.isActive) { if (widget.isActive != oldWidget.isActive) {
if (widget.isActive) { if (videoController.value.isInitialized) {
videoController.play(); if (widget.isActive) {
} else { videoController.play();
videoController.pause(); } else {
videoController.pause();
}
} }
} }
} }
@ -104,42 +94,14 @@ class _VideoWidgetState extends State<VideoWidget> {
@override @override
void dispose() { void dispose() {
_muteWorker.dispose(); _muteWorker.dispose();
_timerResetWorker.dispose();
_hideControlsWorker.dispose();
videoController.dispose(); videoController.dispose();
_hideControlsTimer?.cancel();
super.dispose(); super.dispose();
} }
void _startHideControlsTimer() {
_hideControlsTimer?.cancel();
_hideControlsTimer = Timer(const Duration(seconds: 3), () {
if (mounted) {
setState(() => _showControls = false);
}
});
}
void _onTap({bool ctrlButton = false}) {
if (ctrlButton) {
_startHideControlsTimer();
return;
}
final bool newShowState = !_showControls;
setState(() => _showControls = newShowState);
if (newShowState) {
_startHideControlsTimer();
} else {
_hideControlsTimer?.cancel();
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool muted = settingsController.muted.value; final bool isInitialized = videoController.value.isInitialized;
bool isAudio = widget.details.mime.startsWith('audio'); final bool isAudio = widget.details.mime.startsWith('audio');
Widget mediaContent; Widget mediaContent;
if (isAudio) { if (isAudio) {
@ -153,43 +115,23 @@ class _VideoWidgetState extends State<VideoWidget> {
), ),
); );
} else { } else {
mediaContent = videoController.value.isInitialized mediaContent = isInitialized
? CachedVideoPlayerPlus(videoController) ? CachedVideoPlayerPlus(videoController)
: const Center(child: CircularProgressIndicator()); : const Center(child: CircularProgressIndicator());
} }
return AspectRatio( return AspectRatio(
aspectRatio: videoController.value.isInitialized aspectRatio: isInitialized
? videoController.value.aspectRatio ? videoController.value.aspectRatio
: (isAudio ? 16 / 9 : 9 / 16), : (isAudio ? 16 / 9 : 9 / 16),
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
GestureDetector(onTap: _onTap, child: mediaContent), mediaContent,
AnimatedBuilder( if (isInitialized)
animation: videoController, Positioned.fill(
builder: (context, child) { child: VideoControlsOverlay(controller: videoController),
if (videoController.value.isInitialized && _showControls) { ),
return Positioned.fill(
child: GestureDetector(
onTap: _onTap,
child: Container(
color: Colors.black.withValues(alpha: 0.5),
child: VideoControlsOverlay(
controller: videoController,
onOverlayTap: () => _onTap(ctrlButton: true),
muted: muted,
onMuteToggle: () {
settingsController.toggleMuted();
},
),
),
),
);
}
return const SizedBox.shrink();
},
),
], ],
), ),
); );

View File

@ -264,6 +264,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.1.2" version: "4.1.2"
intl:
dependency: transitive
description:
name: intl
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
url: "https://pub.dev"
source: hosted
version: "0.20.2"
js: js:
dependency: transitive dependency: transitive
description: description:
@ -661,6 +669,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.6" version: "0.7.6"
timeago:
dependency: "direct main"
description:
name: timeago
sha256: b05159406a97e1cbb2b9ee4faa9fb096fe0e2dfcd8b08fcd2a00553450d3422e
url: "https://pub.dev"
source: hosted
version: "3.7.1"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:

View File

@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.4.6+67 version: 1.4.9+70
environment: environment:
sdk: ^3.9.0-100.2.beta sdk: ^3.9.0-100.2.beta
@ -37,6 +37,7 @@ dependencies:
share_plus: ^11.0.0 share_plus: ^11.0.0
flutter_cache_manager: ^3.4.1 flutter_cache_manager: ^3.4.1
pullex: ^1.0.0 pullex: ^1.0.0
timeago: ^3.7.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: