Skip to content

How to. listen power setting notification using this package #912

Answered by halildurmus
alihassan143 asked this question in Q&A
Discussion options

You must be logged in to vote

It's possible to listen to these notifications in Dart, but it requires a bit of setup.

To achieve this, you need to create an invisible Win32 window and run a message loop, which is a blocking operation. Therefore, this must be done in a separate isolate to avoid blocking the main isolate.

Here's an example that listens for GUID_CONSOLE_DISPLAY_STATE and session notifications:

import 'dart:async';
import 'dart:ffi';
import 'dart:isolate';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

void main() async {
  final subscription = onNotification.listen((state) {
    print('Received notification: $state');
  });

  print('Listening notifications for 30 seconds...');

  await

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@halildurmus
Comment options

Answer selected by halildurmus
@alihassan143
Comment options

@halildurmus
Comment options

@alihassan143
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants