💄 Optimize title bar for windows and linux
This commit is contained in:
@@ -31,6 +31,8 @@ class WindowScaffold extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final isMaximized = useState(false);
|
||||||
|
|
||||||
// Add window resize listener for desktop platforms
|
// Add window resize listener for desktop platforms
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
if (!kIsWeb &&
|
if (!kIsWeb &&
|
||||||
@@ -49,11 +51,16 @@ class WindowScaffold extends HookConsumerWidget {
|
|||||||
_WindowSizeObserver(saveWindowSize),
|
_WindowSizeObserver(saveWindowSize),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final maximizeListener = _WindowMaximizeListener(isMaximized);
|
||||||
|
windowManager.addListener(maximizeListener);
|
||||||
|
windowManager.isMaximized().then((max) => isMaximized.value = max);
|
||||||
|
|
||||||
return () {
|
return () {
|
||||||
// Cleanup observer when widget is disposed
|
// Cleanup observer when widget is disposed
|
||||||
WidgetsBinding.instance.removeObserver(
|
WidgetsBinding.instance.removeObserver(
|
||||||
_WindowSizeObserver(saveWindowSize),
|
_WindowSizeObserver(saveWindowSize),
|
||||||
);
|
);
|
||||||
|
windowManager.removeListener(maximizeListener);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -87,47 +94,61 @@ class WindowScaffold extends HookConsumerWidget {
|
|||||||
: MainAxisAlignment.start,
|
: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Platform.isMacOS
|
||||||
'Solar Network',
|
? Text(
|
||||||
textAlign:
|
'Solar Network',
|
||||||
Platform.isMacOS
|
textAlign: TextAlign.center,
|
||||||
? TextAlign.center
|
).padding(horizontal: 12, vertical: 5)
|
||||||
: TextAlign.start,
|
: Row(
|
||||||
).padding(horizontal: 12, vertical: 5),
|
children: [
|
||||||
|
Image.asset(
|
||||||
|
Theme.of(context).brightness == Brightness.dark
|
||||||
|
? 'assets/icons/icon-dark.png'
|
||||||
|
: 'assets/icons/icon.png',
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Solar Network',
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).padding(horizontal: 12, vertical: 5),
|
||||||
),
|
),
|
||||||
if (!Platform.isMacOS)
|
if (!Platform.isMacOS)
|
||||||
IconButton(
|
...([
|
||||||
icon: Icon(Symbols.minimize),
|
IconButton(
|
||||||
onPressed: () => windowManager.minimize(),
|
icon: Icon(Symbols.minimize),
|
||||||
iconSize: 16,
|
onPressed: () => windowManager.minimize(),
|
||||||
padding: EdgeInsets.all(8),
|
iconSize: 16,
|
||||||
constraints: BoxConstraints(),
|
padding: EdgeInsets.all(8),
|
||||||
color: Theme.of(context).iconTheme.color,
|
constraints: BoxConstraints(),
|
||||||
),
|
color: Theme.of(context).iconTheme.color,
|
||||||
if (!Platform.isMacOS)
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Symbols.maximize),
|
icon: Icon(isMaximized.value ? Symbols.fullscreen_exit : Symbols.fullscreen),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await windowManager.isMaximized()) {
|
if (await windowManager.isMaximized()) {
|
||||||
windowManager.restore();
|
windowManager.restore();
|
||||||
} else {
|
} else {
|
||||||
windowManager.maximize();
|
windowManager.maximize();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
iconSize: 16,
|
iconSize: 16,
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.all(8),
|
||||||
constraints: BoxConstraints(),
|
constraints: BoxConstraints(),
|
||||||
color: Theme.of(context).iconTheme.color,
|
color: Theme.of(context).iconTheme.color,
|
||||||
),
|
),
|
||||||
if (!Platform.isMacOS)
|
IconButton(
|
||||||
IconButton(
|
icon: Icon(Symbols.close),
|
||||||
icon: Icon(Symbols.close),
|
onPressed: () => windowManager.hide(),
|
||||||
onPressed: () => windowManager.close(),
|
iconSize: 16,
|
||||||
iconSize: 16,
|
padding: EdgeInsets.all(8),
|
||||||
padding: EdgeInsets.all(8),
|
constraints: BoxConstraints(),
|
||||||
constraints: BoxConstraints(),
|
color: Theme.of(context).iconTheme.color,
|
||||||
color: Theme.of(context).iconTheme.color,
|
),
|
||||||
),
|
]),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -178,6 +199,21 @@ class _WindowSizeObserver extends WidgetsBindingObserver {
|
|||||||
int get hashCode => onSaveWindowSize.hashCode;
|
int get hashCode => onSaveWindowSize.hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _WindowMaximizeListener with WindowListener {
|
||||||
|
final ValueNotifier<bool> isMaximized;
|
||||||
|
_WindowMaximizeListener(this.isMaximized);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onWindowMaximize() {
|
||||||
|
isMaximized.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onWindowUnmaximize() {
|
||||||
|
isMaximized.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final rootScaffoldKey = GlobalKey<ScaffoldState>();
|
final rootScaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
class AppScaffold extends HookConsumerWidget {
|
class AppScaffold extends HookConsumerWidget {
|
||||||
|
Reference in New Issue
Block a user