add fullscreen mode

This commit is contained in:
2025-10-14 20:30:28 +02:00
parent cb8aaaee44
commit af0b6c720d
9 changed files with 140 additions and 56 deletions

View File

@@ -6,6 +6,7 @@ import 'package:hive/hive.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:pdfrx/pdfrx.dart'; import 'package:pdfrx/pdfrx.dart';
import 'package:flutter_fullscreen/flutter_fullscreen.dart';
import 'login_page.dart'; import 'login_page.dart';
@@ -25,6 +26,10 @@ Future<void> main() async {
Hive.init(dir.path); // Needed only if not web Hive.init(dir.path); // Needed only if not web
} }
// setup for flutter_fullscreen
WidgetsFlutterBinding.ensureInitialized();
await FullScreen.ensureInitialized();
runApp(const MyApp()); runApp(const MyApp());
} }

View File

@@ -8,6 +8,7 @@ import 'package:sheetless/api.dart';
import 'package:sheetless/bt_pedal_shortcuts.dart'; import 'package:sheetless/bt_pedal_shortcuts.dart';
import 'package:sheetless/sheet.dart'; import 'package:sheetless/sheet.dart';
import 'package:sheetless/storage_helper.dart'; import 'package:sheetless/storage_helper.dart';
import 'package:flutter_fullscreen/flutter_fullscreen.dart';
class SheetViewerPage extends StatefulWidget { class SheetViewerPage extends StatefulWidget {
final Sheet sheet; final Sheet sheet;
@@ -25,7 +26,8 @@ class SheetViewerPage extends StatefulWidget {
State<SheetViewerPage> createState() => _SheetViewerPageState(); State<SheetViewerPage> createState() => _SheetViewerPageState();
} }
class _SheetViewerPageState extends State<SheetViewerPage> { class _SheetViewerPageState extends State<SheetViewerPage>
with FullScreenListener {
final log = Logger("SheetViewerPage"); final log = Logger("SheetViewerPage");
final StorageHelper storageHelper = StorageHelper(); final StorageHelper storageHelper = StorageHelper();
@@ -37,12 +39,14 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
@override @override
void initState() { void initState() {
FullScreen.addListener(this);
super.initState(); super.initState();
documentLoaded = loadPdf(); documentLoaded = loadPdf();
} }
@override @override
void dispose() { void dispose() {
FullScreen.removeListener(this);
document?.dispose(); // Make sure document gets garbage collected document?.dispose(); // Make sure document gets garbage collected
super.dispose(); super.dispose();
} }
@@ -66,25 +70,16 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
return true; return true;
} }
void toggleFullscreen() { @override
widget.config.fullscreen = !widget.config.fullscreen; void onFullScreenChanged(bool enabled, SystemUiMode? systemUiMode) {
setState(() {
widget.config.fullscreen = enabled;
storageHelper.writeConfig(widget.config); storageHelper.writeConfig(widget.config);
});
if (widget.config.fullscreen) {
log.info("enter fullscreen");
// enter fullscreen
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
overlays: [],
);
} else {
// exit fullscreen
log.info("exit fullscreen");
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
overlays: SystemUiOverlay.values,
);
} }
void toggleFullscreen() {
FullScreen.setFullScreen(!widget.config.fullscreen);
} }
void turnPage(int numTurns) { void turnPage(int numTurns) {
@@ -100,7 +95,9 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
onTurnPageForward: () => turnPage(1), onTurnPageForward: () => turnPage(1),
onTurnPageBackward: () => turnPage(-1), onTurnPageBackward: () => turnPage(-1),
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: widget.config.fullscreen
? null
: AppBar(
title: Text(widget.sheet.name), title: Text(widget.sheet.name),
actions: [ actions: [
IconButton( IconButton(
@@ -127,7 +124,9 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
}); });
}, },
icon: Icon( icon: Icon(
widget.config.twoPageMode ? Icons.filter_1 : Icons.filter_2, widget.config.twoPageMode
? Icons.filter_1
: Icons.filter_2,
), ),
), ),
], ],
@@ -155,12 +154,13 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
// print("Touch at x = ${details.localPosition.dx}"); // print("Touch at x = ${details.localPosition.dx}");
// print("Screenwidth = ${screenWidth}"); // print("Screenwidth = ${screenWidth}");
// Check where the user tapped // Check where the user tapped
// if (details.localPosition.dy < 100) { if (details.localPosition.dy < 100) {
// TODO // TODO
// setState(() { setState(() {
// toggleFullscreen(); toggleFullscreen();
// }); });
if (details.localPosition.dx < screenWidth / 2) { } else if (details.localPosition.dx <
screenWidth / 2) {
// Left half of the screen // Left half of the screen
turnPage(-1); turnPage(-1);
} else { } else {

View File

@@ -7,13 +7,21 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h> #include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <screen_retriever_linux/screen_retriever_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin");
screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
} }

View File

@@ -4,7 +4,9 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux flutter_secure_storage_linux
screen_retriever_linux
url_launcher_linux url_launcher_linux
window_manager
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@@ -7,12 +7,16 @@ import Foundation
import flutter_secure_storage_macos import flutter_secure_storage_macos
import path_provider_foundation import path_provider_foundation
import screen_retriever_macos
import sqflite_darwin import sqflite_darwin
import url_launcher_macos import url_launcher_macos
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
} }

View File

@@ -150,6 +150,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.9.8" version: "0.9.8"
flutter_fullscreen:
dependency: "direct main"
description:
name: flutter_fullscreen
sha256: "37fc83866ded6477efdd5653bed3a6edaaa831dada48a3ca58b2395ce1cc282f"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
flutter_launcher_icons: flutter_launcher_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -504,6 +512,46 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.28.0" version: "0.28.0"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "570dbc8e4f70bac451e0efc9c9bb19fa2d6799a11e6ef04f946d7886d2e23d0c"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
screen_retriever_linux:
dependency: transitive
description:
name: screen_retriever_linux
sha256: f7f8120c92ef0784e58491ab664d01efda79a922b025ff286e29aa123ea3dd18
url: "https://pub.dev"
source: hosted
version: "0.2.0"
screen_retriever_macos:
dependency: transitive
description:
name: screen_retriever_macos
sha256: "71f956e65c97315dd661d71f828708bd97b6d358e776f1a30d5aa7d22d78a149"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
screen_retriever_platform_interface:
dependency: transitive
description:
name: screen_retriever_platform_interface
sha256: ee197f4581ff0d5608587819af40490748e1e39e648d7680ecf95c05197240c0
url: "https://pub.dev"
source: hosted
version: "0.2.0"
screen_retriever_windows:
dependency: transitive
description:
name: screen_retriever_windows
sha256: "449ee257f03ca98a57288ee526a301a430a344a161f9202b4fcc38576716fe13"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@@ -725,6 +773,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.14.0" version: "5.14.0"
window_manager:
dependency: transitive
description:
name: window_manager
sha256: "7eb6d6c4164ec08e1bf978d6e733f3cebe792e2a23fb07cbca25c2872bfdbdcd"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:

View File

@@ -48,6 +48,7 @@ dependencies:
flutter_drawing_board: ^0.9.8 flutter_drawing_board: ^0.9.8
flutter_launcher_icons: ^0.14.4 flutter_launcher_icons: ^0.14.4
hive: ^2.2.3 hive: ^2.2.3
flutter_fullscreen: ^1.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@@ -8,13 +8,19 @@
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h> #include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterSecureStorageWindowsPluginRegisterWithRegistrar( FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar( PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
} }

View File

@@ -5,7 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows flutter_secure_storage_windows
permission_handler_windows permission_handler_windows
screen_retriever_windows
url_launcher_windows url_launcher_windows
window_manager
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST