system_windows 0.1.1 copy "system_windows: ^0.1.1" to clipboard
system_windows: ^0.1.1 copied to clipboard

outdated

Get opened windows and check which one of them is currently focused

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:system_windows/system_windows.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var systemWindows = SystemWindows();

  var windowsToShow = List<Window>.empty();
  var ticks = 0;

  @override
  void initState() {
    super.initState();
    _init();
  }

  void _init() async {
    Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
      final activeApps = await systemWindows.getActiveApps();

      final wl = activeApps
          .map((w) => Window(w.name, w.icon, w.isActive, 0, 0))
          .toList();

      if (windowsToShow.isEmpty) {
        windowsToShow = wl;
      }

      for (var element in wl) {
        if (element.isActive) {
          final activeWindow =
              windowsToShow.firstWhere((window) => window.name == element.name);

          activeWindow.previousActivityForce = activeWindow.activityForce;
          activeWindow.activityForce = activeWindow.activityForce + 100;
        }
      }
      setState(() => ticks = ticks + 100);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: ListView.builder(
          itemCount: windowsToShow.length,
          itemBuilder: (context, index) => Stack(
            children: [
              Row(
                children: [
                  Image.memory(windowsToShow[index].icon),
                  TweenAnimationBuilder<int>(
                    tween: IntTween(
                      begin: windowsToShow[index].previousActivityForce,
                      end: windowsToShow[index].activityForce,
                    ),
                    duration: Duration(milliseconds: 1000),
                    builder: (context, value, widget) => Expanded(
                      flex: value,
                      child: Container(
                        height: 30.0,
                        color: Colors.red,
                      ),
                    ),
                  ),
                  TweenAnimationBuilder<int>(
                    tween: IntTween(
                      begin: windowsToShow[index].activityForce,
                      end: ticks - windowsToShow[index].activityForce,
                    ),
                    duration: Duration(milliseconds: 1000),
                    builder: (context, value, widget) => Expanded(
                      flex: value,
                      child: Container(
                        height: 30,
                      ),
                    ),
                  ),
                ],
              ),
              Padding(
                  padding: EdgeInsets.only(left: 40.0),
                  child: Text(windowsToShow[index].name)),
            ],
          ),
        ),
      ),
    );
  }
}

class Window {
  Window(
    this.name,
    this.icon,
    this.isActive,
    this.activityForce,
    this.previousActivityForce,
  );

  String name;
  Uint8List icon;
  bool isActive;
  int activityForce;
  int previousActivityForce;
}
18
likes
0
pub points
18%
popularity

Publisher

verified publisherdevtalents.com

Get opened windows and check which one of them is currently focused

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on system_windows