Flutter桌面软件开发中使用window_manager自定义关闭、最大化 最小化按钮
Flutter中使用window_manager自定义关闭按钮
一、Flutter中使用window_manager自定义关闭按钮 初始化配置
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 必须加上这一行。
await windowManager.ensureInitialized();
WindowOptions windowOptions = WindowOptions(
size: Size(800, 600),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
runApp(MyApp());
}
二、window_manager自定义关闭、最大化 最小化按钮
import 'package:window_manager/window_manager.dart';
import 'package:flutter/material.dart';
class WindowButtons extends StatefulWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
_WindowButtonsState createState() => _WindowButtonsState();
}
class _WindowButtonsState extends State<WindowButtons> {
@override
Widget build(BuildContext context) {
return const SizedBox(
width: 138,
height: 50,
child: WindowCaption(
brightness: Brightness.light,
backgroundColor: Colors.transparent,
),
);
}
}
三、调用
appBar: AppBar(
toolbarHeight: 30,
title: const DragToMoveArea(
child: SizedBox(
height: 40,
width: double.infinity,
),
),
actions: [if (Platform.isWindows == true) const WindowButtons()],
),