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

discontinued
outdated

An interface to control the native window.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:window_interface/window_interface.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> {
  bool? _isFullScreen;
  Size? _getWindowSize;
  Size? _getMinWindowSize;
  Size? _getMaxWindowSize;

  int _setWindowWidth = 600;
  int _setWindowHeight = 400;
  int _setMinWindowWidth = 500;
  int _setMinWindowHeight = 400;
  int _setMaxWindowWidth = 1600;
  int _setMaxWindowHeight = 900;
  bool _setFullScreen = false;
  bool _setTopMost = false;

  TableRow _rowGetWindowSize() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async {
            var size = await WindowInterface.getWindowSize();
            setState(() => _getWindowSize = size);
          },
          child: const Text("getWindowSize"),
        ),
        Text("${_getWindowSize?.width.toInt()}, ${_getWindowSize?.height.toInt()}"),
      ],
    );
  }

  TableRow _rowSetWindowSize(double maxEditHeight) {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async => await WindowInterface.setWindowSize(
            _setWindowWidth,
            _setWindowHeight,
          ),
          child: const Text("setWindowSize"),
        ),
        Row(
          children: [
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "width: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setWindowWidth"),
                onChanged: (value) {
                  int? width = int.tryParse(value);
                  if (width != null) _setWindowWidth = width;
                },
              ),
            ),
            const SizedBox(width: 10),
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "height: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setWindowHeight"),
                onChanged: (value) {
                  int? height = int.tryParse(value);
                  if (height != null) _setWindowHeight = height;
                },
              ),
            ),
          ],
        ),
      ],
    );
  }

  TableRow _rowGetFullScreen() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async {
            var fullscreen = await WindowInterface.getFullScreen();
            setState(() => _isFullScreen = fullscreen);
          },
          child: const Text("getFullScreen"),
        ),
        Text("$_isFullScreen"),
      ],
    );
  }

  TableRow _rowSetFullScreen() {
    return TableRow(
      children: [
        TableCell(
          verticalAlignment: TableCellVerticalAlignment.middle,
          child: TextButton(
            onPressed: () async => WindowInterface.setFullScreen(_setFullScreen),
            child: const Text("setFullScreen"),
          ),
        ),
        Align(
          alignment: Alignment.centerLeft,
          child: Switch(
            value: _setFullScreen,
            onChanged: (value) {
              setState(() => _setFullScreen = value);
            },
          ),
        ),
      ],
    );
  }

  TableRow _rowToggleFullScreen() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async => WindowInterface.toggleFullScreen(),
          child: const Text("toggleFullScreen"),
        ),
        const Divider(),
      ],
    );
  }

  TableRow _rowGetMinWindowSize() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async {
            var size = await WindowInterface.getWindowMinSize();
            setState(() => _getMinWindowSize = size);
          },
          child: const Text("getWindowMinSize"),
        ),
        Text("${_getMinWindowSize?.width.toInt()}, ${_getMinWindowSize?.height.toInt()}"),
      ],
    );
  }

  TableRow _rowSetMinWindowSize(double maxEditHeight) {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async => await WindowInterface.setWindowMinSize(
            _setMinWindowWidth,
            _setMinWindowHeight,
          ),
          child: const Text("setWindowMinSize"),
        ),
        Row(
          children: [
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "width: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setMinWindowWidth"),
                onChanged: (value) {
                  int? width = int.tryParse(value);
                  if (width != null) _setMinWindowWidth = width;
                },
              ),
            ),
            const SizedBox(width: 10),
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "height: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setMinWindowHeight"),
                onChanged: (value) {
                  int? height = int.tryParse(value);
                  if (height != null) _setMinWindowHeight = height;
                },
              ),
            ),
          ],
        ),
      ],
    );
  }

  TableRow _rowResetMinWindowSize() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async => WindowInterface.resetWindowMinSize(),
          child: const Text("resetWindowMinSize"),
        ),
        const Divider(),
      ],
    );
  }

  TableRow _rowGetMaxWindowSize() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async {
            var size = await WindowInterface.getWindowMaxSize();
            setState(() => _getMaxWindowSize = size);
          },
          child: const Text("getWindowMaxSize"),
        ),
        Text("${_getMaxWindowSize?.width.toInt()}, ${_getMaxWindowSize?.height.toInt()}"),
      ],
    );
  }

  TableRow _rowSetMaxWindowSize(double maxEditHeight) {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async =>
              WindowInterface.setWindowMaxSize(_setMaxWindowWidth, _setMaxWindowHeight),
          child: const Text("setWindowMaxSize"),
        ),
        Row(
          children: [
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "width: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setMaxWindowWidth"),
                onChanged: (value) {
                  int? width = int.tryParse(value);
                  if (width != null) _setMaxWindowWidth = width;
                },
              ),
            ),
            const SizedBox(width: 10),
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  prefixText: "height: ",
                  constraints: BoxConstraints(maxHeight: maxEditHeight),
                ),
                controller: TextEditingController(text: "$_setMaxWindowHeight"),
                onChanged: (value) {
                  int? height = int.tryParse(value);
                  if (height != null) _setMaxWindowHeight = height;
                },
              ),
            ),
          ],
        ),
      ],
    );
  }

  TableRow _rowResetMaxWindowSize() {
    return TableRow(
      children: [
        TextButton(
          onPressed: () async => WindowInterface.resetWindowMaxSize(),
          child: const Text("resetWindowMaxSize"),
        ),
        const Divider(),
      ],
    );
  }

  TableRow _rowSetStayOnTop() {
    return TableRow(
      children: [
        TableCell(
          verticalAlignment: TableCellVerticalAlignment.middle,
          child: TextButton(
            onPressed: () async => WindowInterface.setStayOnTop(_setTopMost),
            child: const Text("setStayOnTop"),
          ),
        ),
        Align(
          alignment: Alignment.centerLeft,
          child: Switch(
            value: _setTopMost,
            onChanged: (value) {
              setState(() => _setTopMost = value);
            },
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    final double maxEditHeight = (Theme.of(context).textTheme.bodyText1?.fontSize ?? 14) * 2 + 8;

    return MaterialApp(
      theme: ThemeData(brightness: Brightness.dark),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Window interface example'),
        ),
        body: Container(
          padding: const EdgeInsets.all(10),
          alignment: Alignment.center,
          child: SingleChildScrollView(
            child: Table(
              defaultVerticalAlignment: TableCellVerticalAlignment.bottom,
              columnWidths: const {
                0: IntrinsicColumnWidth(),
                1: IntrinsicColumnWidth(),
              },
              children: [
                _rowGetWindowSize(),
                _rowGetMinWindowSize(),
                _rowGetMaxWindowSize(),
                _rowSetWindowSize(maxEditHeight),
                _rowSetMinWindowSize(maxEditHeight),
                _rowResetMinWindowSize(),
                _rowSetMaxWindowSize(maxEditHeight),
                _rowResetMaxWindowSize(),
                _rowToggleFullScreen(),
                _rowGetFullScreen(),
                _rowSetFullScreen(),
                _rowSetStayOnTop(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}