-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(title_bar): platform specific title bar
- Loading branch information
Showing
7 changed files
with
59 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,29 @@ | ||
import 'package:bitsdojo_window/bitsdojo_window.dart'; | ||
import 'package:fluent_ui/fluent_ui.dart' show FluentTheme; | ||
import 'package:flutter/material.dart'; | ||
import 'package:platform_ui/platform_ui.dart'; | ||
import 'package:spotube/utils/platform.dart'; | ||
|
||
class TitleBarActionButtons extends StatelessWidget { | ||
final Color? color; | ||
const TitleBarActionButtons({ | ||
Key? key, | ||
this.color, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return TextButtonTheme( | ||
data: TextButtonThemeData( | ||
style: ButtonStyle( | ||
splashFactory: NoSplash.splashFactory, | ||
shape: MaterialStateProperty.all(const RoundedRectangleBorder()), | ||
overlayColor: MaterialStateProperty.all(Colors.black12), | ||
padding: MaterialStateProperty.all(EdgeInsets.zero), | ||
minimumSize: MaterialStateProperty.all(const Size(50, 40)), | ||
maximumSize: MaterialStateProperty.all(const Size(50, 40)), | ||
), | ||
), | ||
child: IconTheme( | ||
data: const IconThemeData(size: 16), | ||
child: Row( | ||
children: [ | ||
TextButton( | ||
onPressed: () { | ||
appWindow.minimize(); | ||
}, | ||
style: ButtonStyle( | ||
foregroundColor: MaterialStateProperty.all( | ||
PlatformTheme.of(context).iconTheme?.color), | ||
), | ||
child: Icon( | ||
Icons.minimize_rounded, | ||
color: color, | ||
)), | ||
TextButton( | ||
onPressed: () async { | ||
appWindow.maximizeOrRestore(); | ||
}, | ||
style: ButtonStyle( | ||
foregroundColor: MaterialStateProperty.all( | ||
PlatformTheme.of(context).iconTheme?.color), | ||
), | ||
child: Icon( | ||
Icons.crop_square_rounded, | ||
color: color, | ||
)), | ||
TextButton( | ||
onPressed: () { | ||
appWindow.close(); | ||
}, | ||
style: ButtonStyle( | ||
foregroundColor: MaterialStateProperty.all( | ||
color ?? PlatformTheme.of(context).iconTheme?.color), | ||
overlayColor: MaterialStateProperty.all(Colors.redAccent), | ||
), | ||
child: const Icon( | ||
Icons.close_rounded, | ||
)), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class PageWindowTitleBar extends StatelessWidget | ||
implements PreferredSizeWidget { | ||
final Widget? leading; | ||
final Widget? center; | ||
final Color? backgroundColor; | ||
final Color? foregroundColor; | ||
final Size? _preferredSize; | ||
const PageWindowTitleBar({ | ||
Key? key, | ||
Size? preferredSize, | ||
this.leading, | ||
this.center, | ||
this.backgroundColor, | ||
this.foregroundColor, | ||
}) : _preferredSize = preferredSize, | ||
super(key: key); | ||
|
||
static Size get staticPreferredSize => Size.fromHeight( | ||
(kIsDesktop ? appWindow.titleBarHeight : 35), | ||
); | ||
|
||
@override | ||
Size get preferredSize => _preferredSize ?? staticPreferredSize; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (kIsMobile) { | ||
return PreferredSize( | ||
preferredSize: const Size.fromHeight(300), | ||
child: Container( | ||
color: backgroundColor, | ||
child: Row( | ||
children: [ | ||
if (leading != null) leading!, | ||
Expanded(child: Center(child: center)), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
return WindowTitleBarBox( | ||
child: Container( | ||
color: backgroundColor ?? | ||
FluentTheme.maybeOf(context)?.micaBackgroundColor, | ||
child: Row( | ||
children: [ | ||
if (kIsMacOS) | ||
SizedBox( | ||
width: MediaQuery.of(context).size.width * 0.045, | ||
), | ||
if (leading != null) leading!, | ||
Expanded(child: MoveWindow(child: Center(child: center))), | ||
if (!kIsMacOS && !kIsMobile) const PlatformWindowButtons() | ||
class PageWindowTitleBar extends PlatformAppBar { | ||
PageWindowTitleBar({ | ||
super.backgroundColor, | ||
List<Widget>? actions, | ||
super.actionsIconTheme, | ||
super.automaticallyImplyLeading = false, | ||
super.centerTitle, | ||
super.foregroundColor, | ||
super.key, | ||
super.leading, | ||
super.leadingWidth, | ||
Widget? center, | ||
super.titleSpacing, | ||
super.titleTextStyle, | ||
super.titleWidth, | ||
super.toolbarOpacity, | ||
super.toolbarTextStyle, | ||
}) : super( | ||
actions: [ | ||
...?actions, | ||
if (!kIsMacOS && !kIsMobile) const PlatformWindowButtons(), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
title: center, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters