diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/pubspec.lock b/example/pubspec.lock index 7a58e4d..c32a7f3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,28 +21,21 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +49,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -67,6 +60,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" fullscreen: dependency: "direct main" description: @@ -74,27 +72,41 @@ packages: relative: true source: path version: "1.0.3" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -106,7 +118,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -127,35 +139,28 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.10.0" diff --git a/lib/fullscreen.dart b/lib/fullscreen.dart index 2566bde..64eecdd 100644 --- a/lib/fullscreen.dart +++ b/lib/fullscreen.dart @@ -1,53 +1,18 @@ import 'dart:async'; -import 'dart:io' show Platform; -import 'package:flutter/services.dart'; -class FullScreen { - // meothod channel instal - static const MethodChannel _channel = const MethodChannel('fullscreen'); +import 'src/fullscreen_native.dart' + if (dart.library.html) 'src/fullscreen_web.dart'; - /// To enable fullscreen mode, pass the fullscreen mode as an argument the the enterFullScreen method of the FullScreen class. - static Future enterFullScreen(FullScreenMode fullScreenMode) async { - if (Platform.isIOS) { - SystemChrome.setEnabledSystemUIOverlays([]); - } else if (Platform.isAndroid) { - try { - if (fullScreenMode == FullScreenMode.EMERSIVE) { - await _channel.invokeMethod('emersive'); - } else if (fullScreenMode == FullScreenMode.EMERSIVE_STICKY) { - await _channel.invokeMethod('emersiveSticky'); - } else if (fullScreenMode == FullScreenMode.LEANBACK) { - await _channel.invokeMethod('leanBack'); - } - } catch (e) { - print(e); - } - } - } +class FullScreen { + static Future enterFullScreen( + [FullScreenMode fullScreenMode = FullScreenMode.EMERSIVE]) => + FullScreenPlatform.enterFullScreen(fullScreenMode); /// to get the current status of the SystemUI - static Future get isFullScreen async { - bool? status; - try { - status = await _channel.invokeMethod("status"); - } catch (e) { - print(e); - } - return status; - } + static Future get isFullScreen => FullScreenPlatform.isFullScreen; /// Exit full screen - static Future exitFullScreen() async { - if (Platform.isIOS) { - SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); - } else if (Platform.isAndroid) { - try { - await _channel.invokeMethod('exitFullScreen'); - } catch (e) { - print(e); - } - } - } + static Future exitFullScreen() => FullScreenPlatform.exitFullScreen(); } enum FullScreenMode { EMERSIVE, EMERSIVE_STICKY, LEANBACK } diff --git a/lib/src/fullscreen_native.dart b/lib/src/fullscreen_native.dart new file mode 100644 index 0000000..7d3ce1d --- /dev/null +++ b/lib/src/fullscreen_native.dart @@ -0,0 +1,54 @@ +import 'dart:async'; +import 'dart:io' show Platform; +import 'package:flutter/services.dart'; +import 'package:fullscreen/fullscreen.dart'; + +class FullScreenPlatform { + // meothod channel instal + static const MethodChannel _channel = const MethodChannel('fullscreen'); + + /// To enable fullscreen mode, pass the fullscreen mode as an argument the the enterFullScreen method of the FullScreen class. + static Future enterFullScreen( + [FullScreenMode fullScreenMode = FullScreenMode.EMERSIVE]) async { + if (Platform.isIOS) { + SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); + } else if (Platform.isAndroid) { + try { + if (fullScreenMode == FullScreenMode.EMERSIVE) { + await _channel.invokeMethod('emersive'); + } else if (fullScreenMode == FullScreenMode.EMERSIVE_STICKY) { + await _channel.invokeMethod('emersiveSticky'); + } else if (fullScreenMode == FullScreenMode.LEANBACK) { + await _channel.invokeMethod('leanBack'); + } + } catch (e) { + print(e); + } + } + } + + /// to get the current status of the SystemUI + static Future get isFullScreen async { + bool? status; + try { + final astatus = await _channel.invokeMethod('status'); + print(astatus); + } catch (e) { + print(e); + } + return status; + } + + /// Exit full screen + static Future exitFullScreen() async { + if (Platform.isIOS) { + SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); + } else if (Platform.isAndroid) { + try { + await _channel.invokeMethod('exitFullScreen'); + } catch (e) { + print(e); + } + } + } +} diff --git a/lib/src/fullscreen_web.dart b/lib/src/fullscreen_web.dart new file mode 100644 index 0000000..0f2497d --- /dev/null +++ b/lib/src/fullscreen_web.dart @@ -0,0 +1,27 @@ +// In order to *not* need this ignore, consider extracting the "web" version +// of your plugin as a separate package, instead of inlining it in the same +// package as the core of your plugin. +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' show window; + +import 'package:fullscreen/fullscreen.dart'; + +/// A web implementation of the FullscreenPlatform of the Fullscreen plugin. +class FullScreenPlatform { + static Future enterFullScreen( + [FullScreenMode fullScreenMode = FullScreenMode.EMERSIVE]) async { + try { + await window.document.documentElement?.requestFullscreen(); + } catch (e) {} + } + + /// to get the current status of the SystemUI + static Future get isFullScreen async { + return window.document.fullscreenElement != null; + } + + /// Exit full screen + static Future exitFullScreen() async { + window.document.exitFullscreen(); + } +} diff --git a/pubspec.lock b/pubspec.lock index 45b93c4..cefc977 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,35 +21,28 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -60,27 +53,46 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -92,7 +104,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -113,35 +125,28 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5b87d5f..bdd5c75 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,9 @@ environment: dependencies: flutter: sdk: flutter - + flutter_web_plugins: + sdk: flutter + dev_dependencies: flutter_test: sdk: flutter @@ -31,6 +33,7 @@ flutter: pluginClass: FullscreenPlugin ios: pluginClass: FullscreenPlugin + web: # To add assets to your plugin package, add an assets section, like this: # assets: