Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Warning and docs about fullscreen methods outside the mobile platforms #3419

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/flame/other/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

```{toctree}
:hidden:

Debugging <debug.md>
Utils <util.md>
Widgets <widgets.md>
Expand Down
7 changes: 7 additions & 0 deletions doc/flame/other/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ On this page you can find documentation for some utility classes and methods.

## Device Class

```{warning}
Many methods in this class work only on mobile platforms (Android and iOS).
erickzanardo marked this conversation as resolved.
Show resolved Hide resolved

Using these methods on other platforms will not have any effect and you will
get a warning printed on your console when running in debug mode.
```

This class can be accessed from `Flame.device` and it has some methods that can be used to control
the state of the device, for instance you can change the screen orientation and set whether the
application should be fullscreen or not.
Expand Down
23 changes: 23 additions & 0 deletions packages/flame/lib/src/device.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

/// Provides methods for controlling the device (e.g. setting the screen to
/// full-screen).
///
/// To use this class, access it via Flame.device.
class Device {
void _warnIfDesktop(String source) {
assert(() {
if (!kIsWeb &&
(Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
// ignore: avoid_print
print(
'Warning: $source is not supported on desktop platforms. '
'It will be a no-op.',
);
}
return true;
}());
}

/// Sets the app to be full-screen (no buttons, bar or notifications on top).
Future<void> fullScreen() {
_warnIfDesktop('fullScreen');
return SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
}

/// Restore the UI mode to the default ([SystemUiMode.edgeToEdge).
Future<void> restoreFullscreen() {
_warnIfDesktop('restoreFullscreen');
return SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
}

/// Sets the preferred orientation (landscape or portrait) for the app.
///
/// When it opens, it will automatically change orientation to the preferred
Expand Down
Loading