new: no titlebar on desktop

This commit is contained in:
lollipopkit
2023-12-09 16:31:18 +08:00
parent cd9d5567fb
commit b2eb96ec16
19 changed files with 237 additions and 123 deletions

View File

@@ -33,8 +33,8 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: const Text('Android'),
appBar: const CustomAppBar(
title: Text('Android'),
),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:provider/provider.dart';
import 'package:toolbox/core/build_mode.dart';
import 'package:toolbox/core/extension/colorx.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/locale.dart';
@@ -123,25 +124,28 @@ class _SettingPageState extends State<SettingPage> {
),
/// Only for debug, this will cause the app to crash
// onDoubleTap: () => context.showRoundDialog(
// title: Text(l10n.attention),
// child: Text(l10n.sureDelete(l10n.all)),
// actions: [
// TextButton(
// onPressed: () {
// Stores.docker.box.deleteFromDisk();
// Stores.server.box.deleteFromDisk();
// Stores.setting.box.deleteFromDisk();
// Stores.history.box.deleteFromDisk();
// Stores.snippet.box.deleteFromDisk();
// Stores.key.box.deleteFromDisk();
// exit(0);
// },
// child: Text(l10n.ok,
// style: const TextStyle(color: Colors.red)),
// ),
// ],
// ),
onDoubleTap: () => context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.askContinue(
'Delete all data from disk, and exit the app?',
)),
actions: [
TextButton(
onPressed: () {
if (!BuildMode.isDebug) return;
Stores.docker.box.deleteFromDisk();
Stores.server.box.deleteFromDisk();
Stores.setting.box.deleteFromDisk();
Stores.history.box.deleteFromDisk();
Stores.snippet.box.deleteFromDisk();
Stores.key.box.deleteFromDisk();
exit(0);
},
child: Text(l10n.ok,
style: const TextStyle(color: Colors.red)),
),
],
),
child: const Icon(Icons.delete),
),
),
@@ -160,8 +164,8 @@ class _SettingPageState extends State<SettingPage> {
_buildSFTP(),
_buildTitle(l10n.editor),
_buildEditor(),
_buildTitle(l10n.fullScreen),
_buildFullScreen(),
if (isDesktop) _buildTitle(l10n.fullScreen),
if (isDesktop) _buildFullScreen(),
const SizedBox(height: 37),
],
),

View File

@@ -34,8 +34,8 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: const Text('iOS'),
appBar: const CustomAppBar(
title: Text('iOS'),
),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),

View File

@@ -1,22 +1,95 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:macos_window_utils/window_manipulator.dart';
import 'package:window_manager/window_manager.dart';
double? _titlebarHeight;
int? _titlebarHeight;
bool _drawTitlebar = false;
class CustomAppBar extends AppBar implements PreferredSizeWidget {
CustomAppBar({
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
const CustomAppBar({
super.key,
super.title,
super.actions,
super.centerTitle,
super.leading,
super.backgroundColor,
}) : super(toolbarHeight: (_titlebarHeight ?? 0) + kToolbarHeight);
this.title,
this.actions,
this.centerTitle,
this.leading,
this.backgroundColor,
});
final Widget? title;
final List<Widget>? actions;
final bool? centerTitle;
final Widget? leading;
final Color? backgroundColor;
@override
Widget build(BuildContext context) {
final bar = AppBar(
key: key,
title: title,
actions: actions,
centerTitle: centerTitle,
leading: leading,
backgroundColor: backgroundColor,
toolbarHeight: (_titlebarHeight ?? 0) + kToolbarHeight,
);
if (!_drawTitlebar) return bar;
return Stack(
children: [
bar,
Positioned(
right: 0,
top: 0,
child: Row(
children: [
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.minimize),
onPressed: () => windowManager.minimize(),
),
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.crop_square),
onPressed: () async {
if (await windowManager.isMaximized()) {
windowManager.unmaximize();
} else {
windowManager.maximize();
}
},
),
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.close),
onPressed: () => windowManager.close(),
),
const SizedBox(width: 8),
],
),
),
],
);
}
static Future<void> updateTitlebarHeight() async {
final newTitlebarHeight = await WindowManipulator.getTitlebarHeight();
if (_titlebarHeight != newTitlebarHeight) {
_titlebarHeight = newTitlebarHeight;
switch (Platform.operatingSystem) {
case 'macos':
final newTitlebarHeight = await windowManager.getTitleBarHeight();
if (_titlebarHeight != newTitlebarHeight) {
_titlebarHeight = newTitlebarHeight;
}
break;
// Draw a titlebar on Linux
case 'linux' || 'windows':
_titlebarHeight = 27;
_drawTitlebar = true;
break;
default:
break;
}
}
@override
Size get preferredSize =>
Size.fromHeight((_titlebarHeight ?? 0) + kToolbarHeight);
}