nexus/lib/widgets/appbar.dart
Henry-Hiles d2ec5f035b
treewide: use dot shorthands where possible
Now this feature is stable, we should use it. I might have missed some usecases, but these can be added in future commits.
2026-06-02 12:50:56 -04:00

70 lines
1.9 KiB
Dart

import "dart:io";
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";
import "package:window_manager/window_manager.dart";
class Appbar extends StatelessWidget implements PreferredSizeWidget {
final Widget? leading;
final Widget? title;
final Color? backgroundColor;
final double? scrolledUnderElevation;
final IList<Widget> actions;
final VoidCallback? onTap;
const Appbar({
super.key,
this.title,
this.onTap,
this.backgroundColor,
this.scrolledUnderElevation,
this.leading,
this.actions = const .empty(),
});
@override
Size get preferredSize => const .fromHeight(kToolbarHeight);
@override
Widget build(BuildContext context) {
Future<void> maximize() async {
final isMaximized = await windowManager.isMaximized();
if (isMaximized) {
return windowManager.unmaximize();
}
return windowManager.maximize();
}
return GestureDetector(
onPanStart: (_) => windowManager.startDragging(),
child: AppBar(
leading: InkWell(onTap: onTap, child: leading),
backgroundColor: backgroundColor,
scrolledUnderElevation: scrolledUnderElevation,
actionsPadding: const .symmetric(horizontal: 8),
title: InkWell(
onTap: onTap,
child: IgnorePointer(child: title),
),
flexibleSpace: GestureDetector(onDoubleTap: maximize),
actions: [
...actions,
if (!(Platform.isAndroid || Platform.isIOS)) ...[
if (!Platform.isLinux)
IconButton(
tooltip: "Maximize window",
onPressed: maximize,
icon: const Icon(Icons.fullscreen),
),
IconButton(
tooltip: "Close window",
onPressed: () => exit(0),
icon: const Icon(Icons.close),
),
],
],
),
);
}
}