From 298b91f05c45672af6b060bc0dfe751318681c4d Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Fri, 9 Aug 2024 18:05:23 +0200 Subject: [PATCH] fix: Exit fullscreen on Firefox (#52, dart-lang/sdk#50857) --- .../lib/provider/app_state_provider.dart | 25 ++++---- .../lib/view/widgets/scaffold.dart | 34 +++++------ wrestling_scoreboard_client/pubspec.lock | 60 ++++++++++--------- wrestling_scoreboard_client/pubspec.yaml | 24 ++++---- 4 files changed, 75 insertions(+), 68 deletions(-) diff --git a/wrestling_scoreboard_client/lib/provider/app_state_provider.dart b/wrestling_scoreboard_client/lib/provider/app_state_provider.dart index 62bca019..43ca1219 100644 --- a/wrestling_scoreboard_client/lib/provider/app_state_provider.dart +++ b/wrestling_scoreboard_client/lib/provider/app_state_provider.dart @@ -1,8 +1,10 @@ +import 'dart:js_interop'; + import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:web/web.dart' as web; import 'package:window_manager/window_manager.dart'; -import 'package:wrestling_scoreboard_client/platform/html.dart' if (dart.library.html) 'dart:html' as html; import 'package:wrestling_scoreboard_client/view/utils.dart'; part 'app_state_provider.g.dart'; @@ -12,13 +14,16 @@ class WindowStateNotifier extends _$WindowStateNotifier with WindowListener { @override Raw> build() async { if (kIsWeb) { - html.document.addEventListener('fullscreenchange', (event) { - if (html.document.fullscreenElement != null) { - _setWindowState(WindowState.fullscreen); - } else { - _setWindowState(WindowState.windowed); - } - }); + web.document.addEventListener( + 'fullscreenchange', + (web.Event event) { + if (web.document.fullscreenElement != null) { + _setWindowState(WindowState.fullscreen); + } else { + _setWindowState(WindowState.windowed); + } + }.toJS, + ); } else if (isDesktop) { windowManager.addListener(this); } else { @@ -93,7 +98,7 @@ class WindowStateNotifier extends _$WindowStateNotifier with WindowListener { Future requestWindowState({required bool isFullscreen}) async { if (isFullscreen) { if (kIsWeb) { - html.document.documentElement?.requestFullscreen(); + await web.document.documentElement?.requestFullscreen().toDart; } else if (isDesktop) { await windowManager.setFullScreen(true); } else { @@ -101,7 +106,7 @@ class WindowStateNotifier extends _$WindowStateNotifier with WindowListener { } } else { if (kIsWeb) { - html.document.exitFullscreen(); + await web.document.exitFullscreen().toDart; } else if (isDesktop) { await windowManager.setFullScreen(false); } else { diff --git a/wrestling_scoreboard_client/lib/view/widgets/scaffold.dart b/wrestling_scoreboard_client/lib/view/widgets/scaffold.dart index 10dadaa0..78b229fb 100644 --- a/wrestling_scoreboard_client/lib/view/widgets/scaffold.dart +++ b/wrestling_scoreboard_client/lib/view/widgets/scaffold.dart @@ -36,27 +36,27 @@ class WindowStateScaffold extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; final alwaysShowAppBar = !hideAppBarOnFullscreen || isMobile; - final appBar = AppBar( - title: appBarTitle, - actions: [ - ...?actions, - IconButton( - icon: const Icon(Icons.fullscreen), - onPressed: () => ref.read(windowStateNotifierProvider.notifier).requestToggleFullScreen(), - tooltip: localizations.toggleFullscreen, - ), - ], - ); - if (alwaysShowAppBar) { - return Scaffold( - appBar: appBar, - body: body, - ); - } return LoadingBuilder( future: ref.watch(windowStateNotifierProvider), builder: (BuildContext context, WindowState data) { final hideAppBar = data == WindowState.fullscreen; + final appBar = AppBar( + title: appBarTitle, + actions: [ + ...?actions, + IconButton( + icon: data.isFullscreen() ? const Icon(Icons.fullscreen_exit) : const Icon(Icons.fullscreen), + onPressed: () => ref.read(windowStateNotifierProvider.notifier).requestToggleFullScreen(), + tooltip: localizations.toggleFullscreen, + ), + ], + ); + if (alwaysShowAppBar) { + return Scaffold( + appBar: appBar, + body: body, + ); + } return Stack( alignment: AlignmentDirectional.topStart, children: [ diff --git a/wrestling_scoreboard_client/pubspec.lock b/wrestling_scoreboard_client/pubspec.lock index 29884e7c..20d48713 100644 --- a/wrestling_scoreboard_client/pubspec.lock +++ b/wrestling_scoreboard_client/pubspec.lock @@ -90,12 +90,13 @@ packages: source: hosted version: "7.0.0" audioplayers_web: - dependency: transitive + dependency: "direct overridden" description: - name: audioplayers_web - sha256: db8fc420dadf80da18e2286c18e746fb4c3b2c5adbf0c963299dde046828886d - url: "https://pub.dev" - source: hosted + path: "packages/audioplayers_web" + ref: HEAD + resolved-ref: "9d25e78d24a687c90ffa76f034c418d2bbe45251" + url: "https://github.com/bluefireteam/audioplayers.git" + source: git version: "5.0.0" audioplayers_windows: dependency: transitive @@ -269,10 +270,10 @@ packages: dependency: transitive description: name: cross_file - sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" + sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670" url: "https://pub.dev" source: hosted - version: "0.3.4+1" + version: "0.3.4+2" crypto: dependency: transitive description: @@ -389,10 +390,10 @@ packages: dependency: transitive description: name: file_selector_web - sha256: "619e431b224711a3869e30dbd7d516f5f5a4f04b265013a50912f39e1abc88c8" + sha256: c4c0ea4224d97a60a7067eca0c8fd419e708ff830e0c83b11a48faf566cec3e7 url: "https://pub.dev" source: hosted - version: "0.9.4+1" + version: "0.9.4+2" file_selector_windows: dependency: transitive description: @@ -673,19 +674,20 @@ packages: package_info_plus: dependency: "direct main" description: - name: package_info_plus - sha256: b93d8b4d624b4ea19b0a5a208b2d6eff06004bc3ce74c06040b120eeadd00ce0 - url: "https://pub.dev" - source: hosted - version: "8.0.0" + path: "packages/package_info_plus/package_info_plus" + ref: HEAD + resolved-ref: "0c5706fa0cda418e552980c93a52e15667e5bb3f" + url: "https://github.com/fluttercommunity/plus_plugins.git" + source: git + version: "8.0.2" package_info_plus_platform_interface: dependency: transitive description: name: package_info_plus_platform_interface - sha256: f49918f3433a3146047372f9d4f1f847511f2acd5cd030e1f44fe5a50036b70e + sha256: ac1f4a4847f1ade8e6a87d1f39f5d7c67490738642e2542f559ec38c37489a66 url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.1" path: dependency: transitive description: @@ -754,10 +756,10 @@ packages: dependency: "direct main" description: name: pdf - sha256: "81d5522bddc1ef5c28e8f0ee40b71708761753c163e0c93a40df56fd515ea0f0" + sha256: "05df53f8791587402493ac97b9869d3824eccbc77d97855f4545cf72df3cae07" url: "https://pub.dev" source: hosted - version: "3.11.0" + version: "3.11.1" pdf_widget_wrapper: dependency: transitive description: @@ -802,10 +804,10 @@ packages: dependency: "direct main" description: name: printing - sha256: cc4b256a5a89d5345488e3318897b595867f5181b8c5ed6fc63bfa5f2044aec3 + sha256: de1889f30b34029fc46e5de6a9841498850b23d32942a9ee810ca36b0cb1b234 url: "https://pub.dev" source: hosted - version: "5.13.1" + version: "5.13.2" pub_semver: dependency: transitive description: @@ -918,10 +920,10 @@ packages: dependency: transitive description: name: shared_preferences_web - sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" + sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.4.2" shared_preferences_windows: dependency: transitive description: @@ -1155,10 +1157,10 @@ packages: dependency: transitive description: name: url_launcher_web - sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a" + sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.3" url_launcher_windows: dependency: transitive description: @@ -1200,21 +1202,21 @@ packages: source: hosted version: "1.1.0" web: - dependency: transitive + dependency: "direct main" description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.0.0" web_socket_channel: dependency: "direct main" description: name: web_socket_channel - sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42" + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b url: "https://pub.dev" source: hosted - version: "2.4.5" + version: "2.4.0" webkit_inspection_protocol: dependency: transitive description: diff --git a/wrestling_scoreboard_client/pubspec.yaml b/wrestling_scoreboard_client/pubspec.yaml index 4bf6cf11..01d44d2e 100644 --- a/wrestling_scoreboard_client/pubspec.yaml +++ b/wrestling_scoreboard_client/pubspec.yaml @@ -27,10 +27,10 @@ dependencies: shared_preferences: ^2.0.13 wrestling_scoreboard_common: path: ../wrestling_scoreboard_common - pdf: ^3.10.1 - printing: ^5.11.1 + pdf: ^3.11.1 + printing: ^5.13.2 url_launcher: ^6.2.2 - package_info_plus: ^8.0.0 + package_info_plus: ^8.0.1 flutter_markdown: ^0.7.1 google_fonts: ^6.1.0 window_manager: ^0.3.8 @@ -40,6 +40,7 @@ dependencies: country: ^4.1.3 file_selector: ^1.0.3 csv: ^6.0.0 + web: ^1.0.0 dev_dependencies: flutter_test: @@ -50,17 +51,16 @@ dev_dependencies: build_runner: ^2.4.7 dependency_overrides: - # TODO(gustl22): Remove when published: https://github.com/DavBfr/dart_pdf/commit/67f451ae1a4726653fb05c946e849f0491d5898a - pdf: + # TODO(gustl22): Remove when published: https://github.com/bluefireteam/audioplayers/pull/1828 + audioplayers_web: git: - url: https://github.com/DavBfr/dart_pdf.git - path: pdf - ref: 5c0425551ab14ea3451ef5e68ec0823ac4952a07 # master - printing: + url: https://github.com/bluefireteam/audioplayers.git + path: packages/audioplayers_web + # TODO(gustl22): Remove when published: https://github.com/fluttercommunity/plus_plugins/commit/05f8afb8fc43bc702ab5e3e14e3cba9d79983446 + package_info_plus: git: - url: https://github.com/DavBfr/dart_pdf.git - path: printing - ref: 5c0425551ab14ea3451ef5e68ec0823ac4952a07 # master + url: https://github.com/fluttercommunity/plus_plugins.git + path: packages/package_info_plus/package_info_plus # TODO(gustl22): Remove when published: https://github.com/rrousselGit/riverpod/commit/d7816cfc6748d9df0f0d9e75e75834f1c89714dc riverpod: git: