1- import 'dart:io' ;
2-
31import 'package:dbus/dbus.dart' ;
42import 'package:flutter/foundation.dart' ;
53import 'package:flutter/material.dart' ;
64import 'package:gsettings/gsettings.dart' ;
75import 'package:libadwaita/src/utils/colors.dart' ;
86import 'package:libadwaita/src/widgets/widgets.dart' ;
97import 'package:libadwaita_core/libadwaita_core.dart' ;
8+ import 'package:universal_io/io.dart' ;
109
1110class HeaderBarStyle {
1211 const HeaderBarStyle ({
@@ -53,32 +52,32 @@ class AdwHeaderBar extends StatefulWidget {
5352 this .start = const [],
5453 this .end = const [],
5554 this .style = const HeaderBarStyle (),
56- required AdwActions actions,
55+ AdwActions ? actions,
5756 AdwControls ? controls,
5857 }) : closeBtn = controls != null
59- ? controls.closeBtn? .call (actions.onClose)
58+ ? controls.closeBtn? .call (actions? .onClose)
6059 : AdwWindowButton (
6160 nativeControls: style.nativeControls,
6261 buttonType: WindowButtonType .close,
63- onPressed: actions.onClose,
62+ onPressed: actions? .onClose,
6463 ),
6564 maximizeBtn = controls != null
66- ? controls.maximizeBtn? .call (actions.onMaximize)
65+ ? controls.maximizeBtn? .call (actions? .onMaximize)
6766 : AdwWindowButton (
6867 nativeControls: style.nativeControls,
6968 buttonType: WindowButtonType .maximize,
70- onPressed: actions.onMaximize,
69+ onPressed: actions? .onMaximize,
7170 ),
7271 minimizeBtn = controls != null
73- ? controls.minimizeBtn? .call (actions.onMinimize)
72+ ? controls.minimizeBtn? .call (actions? .onMinimize)
7473 : AdwWindowButton (
7574 nativeControls: style.nativeControls,
7675 buttonType: WindowButtonType .minimize,
77- onPressed: actions.onMinimize,
76+ onPressed: actions? .onMinimize,
7877 ),
79- onHeaderDrag = actions.onHeaderDrag,
80- onDoubleTap = actions.onDoubleTap,
81- onRightClick = actions.onRightClick;
78+ onHeaderDrag = actions? .onHeaderDrag,
79+ onDoubleTap = actions? .onDoubleTap,
80+ onRightClick = actions? .onRightClick;
8281
8382 /// The leading widget for the headerbar
8483 final List <Widget > start;
@@ -112,19 +111,13 @@ class AdwHeaderBar extends StatefulWidget {
112111}
113112
114113class _AdwHeaderBarState extends State <AdwHeaderBar > {
115- bool get hasWindowControls =>
116- widget.closeBtn != null ||
117- widget.minimizeBtn != null ||
118- widget.maximizeBtn != null ;
114+ bool get hasWindowControls => widget.closeBtn != null || widget.minimizeBtn != null || widget.maximizeBtn != null ;
119115
120- late ValueNotifier <List <String >?> separator =
121- ! widget.style.autoPositionWindowButtons ||
122- ! kIsWeb &&
123- (Platform .isLinux || Platform .isWindows || Platform .isMacOS)
124- ? ValueNotifier (
125- ['' , 'minimize,maximize,close' ],
126- )
127- : ValueNotifier (null );
116+ late ValueNotifier <List <String >?> separator = ! widget.style.autoPositionWindowButtons || ! kIsWeb && (Platform .isLinux || Platform .isWindows || Platform .isMacOS)
117+ ? ValueNotifier (
118+ ['' , 'minimize,maximize,close' ],
119+ )
120+ : ValueNotifier (null );
128121
129122 @override
130123 void initState () {
@@ -138,10 +131,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
138131 (e) => e
139132 .split (',' )
140133 .where (
141- (element) =>
142- element == 'close' ||
143- element == 'maximize' ||
144- element == 'minimize' ,
134+ (element) => element == 'close' || element == 'maximize' || element == 'minimize' ,
145135 )
146136 .join (',' ),
147137 );
@@ -156,8 +146,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
156146
157147 WidgetsBinding .instance.addPostFrameCallback ((_) async {
158148 try {
159- final buttonLayout =
160- await schema.get ('button-layout' ) as DBusString ? ;
149+ final buttonLayout = await schema.get ('button-layout' ) as DBusString ? ;
161150 if (buttonLayout != null ) {
162151 updateSep (buttonLayout.value);
163152 }
@@ -187,9 +176,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
187176 alignment: Alignment .topCenter,
188177 child: Container (
189178 decoration: BoxDecoration (
190- color: ! widget.style.isTransparent
191- ? Theme .of (context).appBarTheme.backgroundColor
192- : null ,
179+ color: ! widget.style.isTransparent ? Theme .of (context).appBarTheme.backgroundColor : null ,
193180 border: ! widget.style.isTransparent
194181 ? Border (
195182 bottom: BorderSide (color: context.borderColor),
@@ -215,15 +202,11 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
215202 leading: Row (
216203 mainAxisSize: MainAxisSize .min,
217204 children: [
218- if (hasWindowControls &&
219- sep != null &&
220- sep[0 ].split (',' ).isNotEmpty) ...[
205+ if (hasWindowControls && sep != null && sep[0 ].split (',' ).isNotEmpty) ...[
221206 SizedBox (width: widget.style.titlebarSpace),
222207 for (var i in sep[0 ].split (',' ))
223208 if (windowButtons[i] != null ) windowButtons[i]! ,
224- if (! widget.style.nativeControls ||
225- ! kIsWeb && Platform .isLinux)
226- SizedBox (width: widget.style.titlebarSpace),
209+ if (! widget.style.nativeControls || ! kIsWeb && Platform .isLinux) SizedBox (width: widget.style.titlebarSpace),
227210 ],
228211 ...widget.start.map (
229212 (e) => Padding (
@@ -243,15 +226,11 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
243226 child: e,
244227 ),
245228 ),
246- if (hasWindowControls &&
247- sep != null &&
248- sep[1 ].split (',' ).isNotEmpty) ...[
229+ if (hasWindowControls && sep != null && sep[1 ].split (',' ).isNotEmpty) ...[
249230 SizedBox (width: widget.style.titlebarSpace),
250231 for (var i in sep[1 ].split (',' ))
251232 if (windowButtons[i] != null ) windowButtons[i]! ,
252- if (! widget.style.nativeControls ||
253- ! kIsWeb && Platform .isLinux)
254- SizedBox (width: widget.style.titlebarSpace),
233+ if (! widget.style.nativeControls || ! kIsWeb && Platform .isLinux) SizedBox (width: widget.style.titlebarSpace),
255234 ],
256235 ],
257236 ),
0 commit comments