From 3ed153fd37e0c38f2b6fec85d58d8fae600bc323 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 23 Dec 2022 13:35:09 +0600 Subject: [PATCH] feat(title_bar): window drag support --- lib/src/widgets/title_bar.dart | 80 ++++++++++++++++++++++++---------- pubspec.yaml | 2 +- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/lib/src/widgets/title_bar.dart b/lib/src/widgets/title_bar.dart index cf3f290..f028480 100644 --- a/lib/src/widgets/title_bar.dart +++ b/lib/src/widgets/title_bar.dart @@ -2,32 +2,64 @@ import 'package:flutter/material.dart'; import 'package:platform_ui/platform_ui.dart'; import 'package:window_manager/window_manager.dart'; -class TitleBar extends PlatformAppBar { - TitleBar({ - List? actions, - super.backgroundColor, - super.centerTitle, - super.leading, - super.leadingWidth, - super.title, - super.titleSpacing, - super.toolbarOpacity, - super.toolbarTextStyle, - super.titleTextStyle, - super.actionsIconTheme, - super.automaticallyImplyLeading, - super.foregroundColor, - super.titleWidth, - super.key, - }) : super( - actions: [ - ...actions ?? [], - const PlatformWindowButtons(), - ], - ); +class TitleBar extends StatelessWidget with PreferredSizeWidget { + final List? actions; + final Widget? leading; + final bool automaticallyImplyLeading; + final Widget? title; + final Color? backgroundColor; + final Color? foregroundColor; + final IconThemeData? actionsIconTheme; + final bool? centerTitle; + final double? titleSpacing; + final double toolbarOpacity; + final double? leadingWidth; + final TextStyle? toolbarTextStyle; + final TextStyle? titleTextStyle; + final double? titleWidth; + + const TitleBar({ + this.actions, + this.leading, + this.automaticallyImplyLeading = true, + 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 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); } diff --git a/pubspec.yaml b/pubspec.yaml index 26bd262..dac7b8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: platform_ui: git: url: https://github.com/KRTirtho/platform_ui.git - ref: 7eb00aef962f282463bc994ca5a6d31cc78f1fe3 + ref: 073cefb9c419fcb01cbdfd6ca2f9714eec23c83b fluent_ui: ^4.1.2 macos_ui: ^1.7.5 libadwaita: ^1.2.5