### Install gnome-screensaver on Linux Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html This command installs the gnome-screensaver utility, which is required for the Desktop ScreenState plugin to function on Linux systems. ```bash sudo apt-get install gnome-screensaver ``` -------------------------------- ### Install GLib for Linux Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html On Linux, install the GLib library if you plan to use the gdbus monitor service, which is often more reliable than dbus-monitor. ```bash sudo apt-get install glib2 ``` -------------------------------- ### Get Singleton Instance Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/instance.html Provides access to the singleton instance of DesktopScreenState. If the instance has not been created yet, it will be created upon first access. ```APIDOC ## instance property DesktopScreenState get instance ### Description Provides access to the singleton instance of `DesktopScreenState`. This property ensures that only one instance of `DesktopScreenState` exists throughout the application. ### Method `get` ### Endpoint `DesktopScreenState.instance` ### Implementation ```dart static DesktopScreenState get instance => _instance ??= _createInstance(); ``` ### Usage ```dart final screenState = DesktopScreenState.instance; // Now you can use the screenState object to manage screen states. ``` ``` -------------------------------- ### Listen for Window Active Events Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html Use DesktopScreenState.instance.isActive to get a ValueListenable that provides real-time updates on whether the window is active or not. You can access the current value and add listeners for changes. ```dart final ValueListenable event = DesktopScreenState.instance.isActive; final bool active = event.value; event.addListener(() { debugPrint("screen is on or off: ${event.value}"); }); ``` -------------------------------- ### Get Singleton Instance of DesktopScreenState Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/instance.html Access the singleton instance of DesktopScreenState. This ensures only one instance of the class is created and used throughout the application. It uses lazy initialization, creating the instance only when it's first accessed. ```dart static DesktopScreenState get instance => _instance ??= _createInstance(); ``` -------------------------------- ### Get Current Screen State Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html Access DesktopScreenState.instance.state to retrieve the current state of the screen, such as awaked, sleep, locked, or unlocked. Use a switch statement to handle each state. ```dart final ScreenState state = DesktopScreenState.instance.state; switch (state) { case ScreenState.awaked: debugPrint("Screen is on"); break; case ScreenState.sleep: debugPrint("Screen is sleep"); break; case ScreenState.locked: debugPrint("Screen is locked"); break; case ScreenState.unlocked: debugPrint("Screen is unlocked"); break; } ``` -------------------------------- ### Get isActive Property Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/isActive.html This code shows how to access the isActive property, which returns a ValueListenable. This listenable can be used to observe changes in the screen's active state. ```dart ValueListenable get isActive => _activeState; ``` -------------------------------- ### DesktopScreenState.instance Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState-class.html Provides a singleton instance of the DesktopScreenState class. ```APIDOC ## DesktopScreenState.instance ### Description Provides a singleton instance of the DesktopScreenState class. ### Static Properties - **instance** (DesktopScreenState) - The singleton instance of DesktopScreenState. ``` -------------------------------- ### Configure Linux Monitor Service and Cleanup Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html In your main() function, set the Linux monitor service and ensure proper cleanup by hooking into process exit signals. This prevents background processes from accumulating. ```dart import 'package:desktop_screenstate/desktop_screenstate.dart'; import 'package:flutter/foundation.dart'; import 'package:process_run/process_run.dart'; void main() { DesktopScreenState.linuxMonitor = ScreenStateMonitor.gdbus; /// Hook into the process exit signals to clean up processes ProcessSignal.sigint.watch().listen((_) => shutdownApp()); ProcessSignal.sigterm.watch().listen((_) => shutdownApp()); runApp(MyApp()); } void shutdownApp() { try { DesktopScreenState.dispose(); // ... Add your custom cleanup logic here ... } finally { exit(0); } } ``` -------------------------------- ### DesktopScreenState.isActive Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState-class.html A listenable value representing the current screen state. ```APIDOC ## DesktopScreenState.isActive ### Description A listenable value that provides the current screen state. ### Properties - **isActive** (ValueListenable) - A listenable value for the screen state. ``` -------------------------------- ### DesktopScreenState.linuxMonitor Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState-class.html Allows setting the screen state monitor to be used on Linux. ```APIDOC ## DesktopScreenState.linuxMonitor ### Description Set the screen state monitor to use on Linux. ### Static Properties - **linuxMonitor** (ScreenStateMonitor) - Getter/setter for the screen state monitor on Linux. ``` -------------------------------- ### Add desktop_screenstate to pubspec.yaml Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html Add this line to your pubspec.yaml file to include the desktop_screenstate package in your project. ```yaml desktop_screenstate: $latest_version ``` -------------------------------- ### Add Windows Header for Screen State Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html Include the winuser.h header and declare a power notification handle in the FlutterWindow class for Windows. ```cpp #include ... + HPOWERNOTIFY power_notification_handle_ = nullptr; ``` -------------------------------- ### DesktopScreenState.dispose Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState-class.html Disposes of the DesktopScreenState instance. ```APIDOC ## DesktopScreenState.dispose() ### Description Disposes of the DesktopScreenState instance. ### Static Methods - **dispose()** - void ``` -------------------------------- ### dispose() Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/dispose.html This static method is responsible for cleaning up the state of the DesktopScreenState. It sets a flag to indicate disposal, stops the D-Bus monitor on Linux, and stops the GDBus monitor on Linux. ```APIDOC ## dispose() static method ### Description Cleans up resources and stops background monitoring processes. ### Method Signature `void dispose()` ### Implementation Details - Sets `_disposing` to `true`. - Calls `_stopDbusLinuxMonitor()`. - Calls `_stopGdbusLinuxMonitor()`. ``` -------------------------------- ### ScreenStateMonitor Methods Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenStateMonitor.html This snippet lists the methods available for the ScreenStateMonitor enum, such as noSuchMethod and toString. ```APIDOC ## Methods noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited tostring() → String A string representation of this object. inherited ``` -------------------------------- ### Set Linux Screen State Monitor Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/linuxMonitor.html Assigns the D-Bus implementation as the screen state monitor for Linux. This is the default behavior. ```dart static var linuxMonitor = ScreenStateMonitor.dbus; ``` -------------------------------- ### Initialize and Unregister Windows Power Notifications Source: https://pub.dev/documentation/desktop_screenstate/latest/index.html Register for power notifications on window creation and unregister on destruction in the FlutterWindow class for Windows. Requires linking wtsapi32.lib. ```cpp #include #pragma comment( lib, "wtsapi32.lib" ) ... FlutterWindow::~FlutterWindow() { + if (power_notification_handle_) { + UnregisterPowerSettingNotification(power_notification_handle_); + } } ... bool FlutterWindow::OnCreate() { ... + power_notification_handle_ = RegisterPowerSettingNotification(GetHandle(), &GUID_CONSOLE_DISPLAY_STATE, DEVICE_NOTIFY_WINDOW_HANDLE); + WTSRegisterSessionNotification(GetHandle(),NOTIFY_FOR_THIS_SESSION); return true; } ``` -------------------------------- ### ScreenStateMonitor Properties Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenStateMonitor.html This snippet details the properties available for the ScreenStateMonitor enum, including hashCode, index, name, and runtimeType. ```APIDOC ## Properties hashCode → int The hash code for this object. no setterinherited index → int A numeric identifier for the enumerated value. no setterinherited name → String Available on Enum, provided by the EnumName extension The name of the enum value. no setter runtimeType → Type A representation of the runtime type of the object. no setterinherited ``` -------------------------------- ### ScreenState Enum Methods Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenState.html The ScreenState enum inherits methods like noSuchMethod and toString. ```APIDOC ## Methods noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. inherited toString() → String A string representation of this object. inherited ``` -------------------------------- ### ScreenStateMonitor Constants Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenStateMonitor.html This snippet highlights the constants associated with the ScreenStateMonitor enum, including the 'values' list. ```APIDOC ## Constants values → const List A constant List of the values in this enum, in order of their declaration. ``` -------------------------------- ### ScreenStateMonitor Operators Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenStateMonitor.html This snippet shows the operators available for the ScreenStateMonitor enum, specifically the equality operator. ```APIDOC ## Operators operator ==(Object other) → bool The equality operator. inherited ``` -------------------------------- ### isActive Property Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/isActive.html The isActive property returns a ValueListenable that can be used to observe changes in the screen state. ```APIDOC ## isActive Property ### Description This property returns a `ValueListenable` which emits the current screen state. ### Method Signature ```dart ValueListenable get isActive ``` ### Implementation ```dart ValueListenable get isActive => _activeState; ``` ``` -------------------------------- ### ScreenState Enum Constants Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenState.html The ScreenState enum provides a constant list of all its values. ```APIDOC ## Constants values → const List A constant List of the values in this enum, in order of their declaration. ``` -------------------------------- ### ScreenState Enum Properties Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenState.html The ScreenState enum provides properties such as hashCode, index, name, and runtimeType. ```APIDOC ## Properties hashCode → int The hash code for this object. no setterinherited index → int A numeric identifier for the enumerated value. no setterinherited name → String Available on Enum, provided by the EnumName extension The name of the enum value. no setter runtimeType → Type A representation of the runtime type of the object. no setterinherited ``` -------------------------------- ### ScreenStateMonitor Enum Values Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenStateMonitor.html This snippet shows the available values for the ScreenStateMonitor enum, which are used to specify the screen state monitor. ```APIDOC ## ScreenStateMonitor Enum Which screen state monitor to use on Linux ### Values dbus → const ScreenStateMonitor gdbus → const ScreenStateMonitor ``` -------------------------------- ### Dispose Resources and Stop Monitors Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/DesktopScreenState/dispose.html Call this static method to properly shut down the screen state monitoring services. It ensures that all background processes related to D-Bus monitoring are terminated. ```dart static void dispose() { _disposing = true; _stopDbusLinuxMonitor(); _stopGdbusLinuxMonitor(); } ``` -------------------------------- ### ScreenState Enum Operators Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenState.html The ScreenState enum supports the equality operator (==). ```APIDOC ## Operators operator ==(Object other) → bool The equality operator. inherited ``` -------------------------------- ### ScreenState Enum Values Source: https://pub.dev/documentation/desktop_screenstate/latest/desktop_screenstate/ScreenState.html The ScreenState enum has the following possible values: sleep, awaked, locked, and unlocked. ```APIDOC ## Enum Values sleep → const ScreenState awaked → const ScreenState locked → const ScreenState unlocked → const ScreenState ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.