From e1be7bd5e6d9115cfa26054096ff36197225ba00 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 26 Aug 2022 23:39:52 +0200 Subject: [PATCH] hiding appbar --- lib/shufflescreen.dart | 2 +- lib/videoscreen_desktop.dart | 51 +++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/shufflescreen.dart b/lib/shufflescreen.dart index 8457a3e..cb66419 100644 --- a/lib/shufflescreen.dart +++ b/lib/shufflescreen.dart @@ -33,7 +33,7 @@ class _ShuffleScreenState extends State { double width = MediaQuery.of(context).size.width; return PreviewGrid( videoLoader: () { - return loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2); + return loadData((isTV() ? width ~/ 200 : width ~/ 275) * 2); }, footerBuilder: (state) => Column( children: [ diff --git a/lib/videoscreen_desktop.dart b/lib/videoscreen_desktop.dart index a82de67..06ef67e 100644 --- a/lib/videoscreen_desktop.dart +++ b/lib/videoscreen_desktop.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'dart:math'; @@ -10,6 +11,7 @@ import 'package:video_player/video_player.dart'; import 'api/api.dart'; import 'api/token.dart'; +import 'log/log.dart'; import 'platform.dart'; class VideoScreen extends StatefulWidget { @@ -21,13 +23,14 @@ class VideoScreen extends StatefulWidget { } class _VideoScreenState extends State { - Player? _player = - isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null; + Player? _player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null; ChewieController? _chewieController; + bool _appBarVisible = true; + Timer? _appBarTimer; + void loadData() async { - final data = - await API.query("video", "loadVideo", {'MovieId': widget.metaData.id}); + final data = await API.query("video", "loadVideo", {'MovieId': widget.metaData.id}); final d = jsonDecode(data); @@ -47,8 +50,7 @@ class _VideoScreenState extends State { autoStart: true, // default ); } else { - final VideoPlayerController _controller = - VideoPlayerController.network(path); + final VideoPlayerController _controller = VideoPlayerController.network(path); await _controller.initialize(); _chewieController = ChewieController( @@ -71,18 +73,15 @@ class _VideoScreenState extends State { if (isDesktop()) { RawKeyboard.instance.addListener((value) { if (value.logicalKey == LogicalKeyboardKey.arrowRight) { - _player - ?.seek(_player!.position.position! + const Duration(seconds: 5)); + _player?.seek(_player!.position.position! + const Duration(seconds: 5)); } else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) { - _player - ?.seek(_player!.position.position! + const Duration(seconds: -5)); + _player?.seek(_player!.position.position! + const Duration(seconds: -5)); } }); } loadData(); - - // todo hide appbar after some seonds + _setAppBarTimer(); } @override @@ -96,13 +95,35 @@ class _VideoScreenState extends State { } } + void _setAppBarTimer() { + _appBarTimer?.cancel(); + _appBarTimer = Timer( + Duration(seconds: 3), + () { + setState(() { + _appBarVisible = false; + }); + }, + ); + } + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.metaData.title), + extendBody: true, + extendBodyBehindAppBar: true, + appBar: _appBarVisible ? AppBar(title: Text(widget.metaData.title)) : null, + body: MouseRegion( + onHover: (PointerEvent event) { + if (event.delta.dx != 0 || event.delta.dy != 0) { + setState(() { + _appBarVisible = true; + }); + _setAppBarTimer(); + } + }, + child: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()), ), - body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()), ); }