feat(title_bar): window drag support

This commit is contained in:
Kingkor Roy Tirtho 2022-12-23 13:35:09 +06:00
parent e5c59720da
commit 3ed153fd37
2 changed files with 57 additions and 25 deletions

View File

@ -2,32 +2,64 @@ import 'package:flutter/material.dart';
import 'package:platform_ui/platform_ui.dart'; import 'package:platform_ui/platform_ui.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
class TitleBar extends PlatformAppBar { class TitleBar extends StatelessWidget with PreferredSizeWidget {
TitleBar({ final List<Widget>? actions;
List<Widget>? actions, final Widget? leading;
super.backgroundColor, final bool automaticallyImplyLeading;
super.centerTitle, final Widget? title;
super.leading, final Color? backgroundColor;
super.leadingWidth, final Color? foregroundColor;
super.title, final IconThemeData? actionsIconTheme;
super.titleSpacing, final bool? centerTitle;
super.toolbarOpacity, final double? titleSpacing;
super.toolbarTextStyle, final double toolbarOpacity;
super.titleTextStyle, final double? leadingWidth;
super.actionsIconTheme, final TextStyle? toolbarTextStyle;
super.automaticallyImplyLeading, final TextStyle? titleTextStyle;
super.foregroundColor, final double? titleWidth;
super.titleWidth,
super.key, const TitleBar({
}) : super( this.actions,
actions: [ this.leading,
...actions ?? [], this.automaticallyImplyLeading = true,
const PlatformWindowButtons(), this.title,
], this.backgroundColor,
); this.foregroundColor,
this.actionsIconTheme,
this.centerTitle,
this.titleSpacing,
this.toolbarOpacity = 1.0,
this.leadingWidth,
this.toolbarTextStyle,
this.titleWidth,
this.titleTextStyle,
Key? key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DragToMoveArea(child: super.build(context)); return PlatformAppBar(
automaticallyImplyLeading: automaticallyImplyLeading,
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
centerTitle: centerTitle,
actionsIconTheme: actionsIconTheme,
leading: leading,
leadingWidth: leadingWidth,
title: title,
titleSpacing: titleSpacing,
toolbarOpacity: toolbarOpacity,
toolbarTextStyle: toolbarTextStyle,
titleTextStyle: titleTextStyle,
titleWidth: titleWidth,
onDrag: () => windowManager.startDragging(),
actions: [
...?actions,
const PlatformWindowButtons(),
],
);
} }
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
} }

View File

@ -33,7 +33,7 @@ dependencies:
platform_ui: platform_ui:
git: git:
url: https://github.com/KRTirtho/platform_ui.git url: https://github.com/KRTirtho/platform_ui.git
ref: 7eb00aef962f282463bc994ca5a6d31cc78f1fe3 ref: 073cefb9c419fcb01cbdfd6ca2f9714eec23c83b
fluent_ui: ^4.1.2 fluent_ui: ^4.1.2
macos_ui: ^1.7.5 macos_ui: ^1.7.5
libadwaita: ^1.2.5 libadwaita: ^1.2.5