window_interface 0.1.2
window_interface: ^0.1.2 copied to clipboard
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 _setWindowMinWidth = 500;
int _setWindowMinHeight = 400;
int _setWindowMaxWidth = 1600;
int _setWindowMaxHeight = 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 isFullScreen = await WindowInterface.getFullScreen();
setState(() => _isFullScreen = isFullScreen);
},
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(
_setWindowMinWidth,
_setWindowMinHeight,
),
child: const Text("setWindowMinSize"),
),
Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixText: "width: ",
constraints: BoxConstraints(maxHeight: maxEditHeight),
),
controller: TextEditingController(text: "$_setWindowMinWidth"),
onChanged: (value) {
int? width = int.tryParse(value);
if (width != null) _setWindowMinWidth = width;
},
),
),
const SizedBox(width: 10),
Expanded(
child: TextField(
decoration: InputDecoration(
prefixText: "height: ",
constraints: BoxConstraints(maxHeight: maxEditHeight),
),
controller: TextEditingController(text: "$_setWindowMinHeight"),
onChanged: (value) {
int? height = int.tryParse(value);
if (height != null) _setWindowMinHeight = 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(_setWindowMaxWidth, _setWindowMaxHeight),
child: const Text("setWindowMaxSize"),
),
Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixText: "width: ",
constraints: BoxConstraints(maxHeight: maxEditHeight),
),
controller: TextEditingController(text: "$_setWindowMaxWidth"),
onChanged: (value) {
int? width = int.tryParse(value);
if (width != null) _setWindowMaxWidth = width;
},
),
),
const SizedBox(width: 10),
Expanded(
child: TextField(
decoration: InputDecoration(
prefixText: "height: ",
constraints: BoxConstraints(maxHeight: maxEditHeight),
),
controller: TextEditingController(text: "$_setWindowMaxHeight"),
onChanged: (value) {
int? height = int.tryParse(value);
if (height != null) _setWindowMaxHeight = 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(),
],
),
),
),
),
);
}
}