Remove yaru dep
This commit is contained in:
parent
a15fae89eb
commit
26a2bd3f5e
21 changed files with 291 additions and 311 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:adwaita_icons/adwaita_icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:brook/providers/decorations_provider.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
import 'package:brook/models/decoration_type.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
||||
final String title;
|
||||
|
|
@ -11,42 +13,61 @@ class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize => const YaruWindowTitleBar().preferredSize;
|
||||
Size get preferredSize => AppBar().preferredSize;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final window = YaruWindow.of(context);
|
||||
|
||||
List<Widget> getControl(List<YaruWindowControlType> types) => [
|
||||
const SizedBox(width: 6),
|
||||
List<Widget> getControl(List<DecorationType> types) => [
|
||||
SizedBox(width: 6),
|
||||
...types.map(
|
||||
(type) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: YaruWindowControl(
|
||||
type: type,
|
||||
onTap: switch (type) {
|
||||
YaruWindowControlType.close => window.close,
|
||||
YaruWindowControlType.maximize => () => window.state().then(
|
||||
(state) => state.isMaximized!
|
||||
? window.restore()
|
||||
: window.maximize(),
|
||||
(type) {
|
||||
final decoration = switch (type) {
|
||||
DecorationType.close => (
|
||||
onClick: windowManager.close,
|
||||
icon: AdwaitaIcons.window_close,
|
||||
),
|
||||
DecorationType.maximize => (
|
||||
onClick: windowManager.maximize,
|
||||
icon: AdwaitaIcons.window_maximize,
|
||||
),
|
||||
DecorationType.minimize => (
|
||||
onClick: windowManager.minimize,
|
||||
icon: AdwaitaIcons.window_minimize,
|
||||
),
|
||||
DecorationType.restore => (
|
||||
onClick: windowManager.restore,
|
||||
icon: AdwaitaIcons.window_restore,
|
||||
),
|
||||
};
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(4),
|
||||
onPressed: decoration.onClick,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
YaruWindowControlType.minimize => window.minimize,
|
||||
YaruWindowControlType.restore => window.restore,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
icon: AdwaitaIcon(decoration.icon),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
SizedBox(width: 6),
|
||||
];
|
||||
|
||||
final decorations = ref.watch(decorationsProvider);
|
||||
|
||||
return YaruWindowTitleBar(
|
||||
return AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
title: Text(title),
|
||||
leading: Row(children: [
|
||||
SizedBox(width: 12),
|
||||
...getControl(decorations.leading),
|
||||
if (Navigator.of(context).canPop())
|
||||
BackButton(
|
||||
style: ButtonStyle(
|
||||
|
|
@ -55,12 +76,9 @@ class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
|||
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
),
|
||||
),
|
||||
...getControl(decorations.leading)
|
||||
]),
|
||||
buttonPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
actions: getControl(decorations.trailing),
|
||||
border: BorderSide.none,
|
||||
style: YaruTitleBarStyle.undecorated,
|
||||
centerTitle: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue