Initial commit
This commit is contained in:
parent
32e425f961
commit
e94d583b8b
67 changed files with 2516 additions and 698 deletions
66
lib/widgets/appbar.dart
Normal file
66
lib/widgets/appbar.dart
Normal file
|
@ -0,0 +1,66 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:canal/providers/decorations_provider.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
|
||||
class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
||||
final String title;
|
||||
const Appbar({
|
||||
required this.title,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize => const YaruWindowTitleBar().preferredSize;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final window = YaruWindow.of(context);
|
||||
|
||||
List<Widget> getControl(List<YaruWindowControlType> types) => [
|
||||
const 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(),
|
||||
),
|
||||
YaruWindowControlType.minimize => window.minimize,
|
||||
YaruWindowControlType.restore => window.restore,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
];
|
||||
|
||||
final decorations = ref.watch(decorationsProvider);
|
||||
|
||||
return YaruWindowTitleBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
title: Text(title),
|
||||
leading: Row(children: [
|
||||
SizedBox(width: 12),
|
||||
if (Navigator.of(context).canPop())
|
||||
BackButton(
|
||||
style: ButtonStyle(
|
||||
iconSize: WidgetStatePropertyAll(20),
|
||||
minimumSize: WidgetStatePropertyAll(Size.square(0)),
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
),
|
||||
),
|
||||
...getControl(decorations.leading)
|
||||
]),
|
||||
buttonPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
actions: getControl(decorations.trailing),
|
||||
border: BorderSide.none,
|
||||
style: YaruTitleBarStyle.undecorated,
|
||||
);
|
||||
}
|
||||
}
|
Reference in a new issue