window_activator 0.1.0+1 copy "window_activator: ^0.1.0+1" to clipboard
window_activator: ^0.1.0+1 copied to clipboard

outdated

A simple plugin for macos to activate the application window (i.e bring it to the front)

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:window_activator/window_activator.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  void setWindowAsFocus() async {
    await Future.delayed(const Duration(seconds: 5));

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      await WindowActivator.activateWindow();
    } on PlatformException catch (e) {
      print(e);
      print('failed to set focus');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: FlatButton(
            child: Text('Set focus'),
            onPressed: setWindowAsFocus,
          ),
        ),
      ),
    );
  }
}
1
likes
40
pub points
28%
popularity

Publisher

unverified uploader

A simple plugin for macos to activate the application window (i.e bring it to the front)

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on window_activator