dotup_flutter_active_window 0.0.2 dotup_flutter_active_window: ^0.0.2 copied to clipboard
A flutter plugin to get active foreground window on MacOS, Windows and Linux.
import 'package:dotup_flutter_active_window/ActiveWindowInfo.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:dotup_flutter_active_window/dotup_flutter_active_window.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ActiveWindowInfo? _windowInfo;
@override
void initState() {
super.initState();
initPlatformState();
final filterFromDb = ActiveWindowFilter(value: 'dotup_', field: ActiveWindowProperty.title);
final windowObserver = ActiveWindowObserver()
// ..addDefaultPrivateFilter()
// ..addFilter((windowInfo) => windowInfo?.title.contains('main') == false)
// ..addFilter(ActiveWindowFilterGenerator().generate(filterFromDb))
..listen((event) {
print(event);
});
windowObserver.start();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
ActiveWindowInfo? windowInfo;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
windowInfo = await DotupFlutterActiveWindow.getActiveWindowInfo;
} on PlatformException {
rethrow;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_windowInfo = windowInfo;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_windowInfo\n'),
),
),
);
}
}