desktop_lifecycle 0.0.1 desktop_lifecycle: ^0.0.1 copied to clipboard
Allow your flutter desktop application to perceive whether the window is activated.
import 'package:desktop_lifecycle/desktop_lifecycle.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: const [
FocusLifecycleState(),
],
),
),
);
}
}
class FocusLifecycleState extends StatelessWidget {
const FocusLifecycleState({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: DesktopLifecycle.instance.isActive,
builder: (context, child) {
final active = DesktopLifecycle.instance.isActive.value;
return Text('active: ${active ? "active" : "inactive"}');
});
}
}