sys_app_bar.dart 938 B

1234567891011121314151617181920212223242526272829303132333435
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:window_manager/window_manager.dart';
  4. class SysAppBar extends StatelessWidget implements PreferredSizeWidget {
  5. final double? toolbarHeight;
  6. final Widget? title;
  7. final List<Widget>? actions;
  8. const SysAppBar({Key? key, this.toolbarHeight, this.title, this.actions}) : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. List<Widget> acs = [];
  12. if (actions != null) {
  13. acs.addAll(actions!);
  14. }
  15. if (Platform.isWindows || Platform.isLinux) {
  16. acs.add(CloseButton(onPressed: () => windowManager.close()));
  17. }
  18. return GestureDetector(
  19. onPanStart: (_) => windowManager.startDragging(),
  20. child: AppBar(
  21. toolbarHeight: preferredSize.height,
  22. title: title,
  23. actions: acs,
  24. ),
  25. );
  26. }
  27. @override
  28. Size get preferredSize => Size.fromHeight(toolbarHeight ?? kToolbarHeight);
  29. }