1
- import 'package:universal_io/io.dart' ;
2
-
3
1
import 'package:dbus/dbus.dart' ;
4
2
import 'package:flutter/foundation.dart' ;
5
3
import 'package:flutter/material.dart' ;
6
4
import 'package:gsettings/gsettings.dart' ;
7
5
import 'package:libadwaita/src/utils/colors.dart' ;
8
6
import 'package:libadwaita/src/widgets/widgets.dart' ;
9
7
import 'package:libadwaita_core/libadwaita_core.dart' ;
8
+ import 'package:universal_io/io.dart' ;
10
9
11
10
class HeaderBarStyle {
12
11
const HeaderBarStyle ({
@@ -53,32 +52,32 @@ class AdwHeaderBar extends StatefulWidget {
53
52
this .start = const [],
54
53
this .end = const [],
55
54
this .style = const HeaderBarStyle (),
56
- required AdwActions actions,
55
+ AdwActions ? actions,
57
56
AdwControls ? controls,
58
57
}) : closeBtn = controls != null
59
- ? controls.closeBtn? .call (actions.onClose)
58
+ ? controls.closeBtn? .call (actions? .onClose)
60
59
: AdwWindowButton (
61
60
nativeControls: style.nativeControls,
62
61
buttonType: WindowButtonType .close,
63
- onPressed: actions.onClose,
62
+ onPressed: actions? .onClose,
64
63
),
65
64
maximizeBtn = controls != null
66
- ? controls.maximizeBtn? .call (actions.onMaximize)
65
+ ? controls.maximizeBtn? .call (actions? .onMaximize)
67
66
: AdwWindowButton (
68
67
nativeControls: style.nativeControls,
69
68
buttonType: WindowButtonType .maximize,
70
- onPressed: actions.onMaximize,
69
+ onPressed: actions? .onMaximize,
71
70
),
72
71
minimizeBtn = controls != null
73
- ? controls.minimizeBtn? .call (actions.onMinimize)
72
+ ? controls.minimizeBtn? .call (actions? .onMinimize)
74
73
: AdwWindowButton (
75
74
nativeControls: style.nativeControls,
76
75
buttonType: WindowButtonType .minimize,
77
- onPressed: actions.onMinimize,
76
+ onPressed: actions? .onMinimize,
78
77
),
79
- onHeaderDrag = actions.onHeaderDrag,
80
- onDoubleTap = actions.onDoubleTap,
81
- onRightClick = actions.onRightClick;
78
+ onHeaderDrag = actions? .onHeaderDrag,
79
+ onDoubleTap = actions? .onDoubleTap,
80
+ onRightClick = actions? .onRightClick;
82
81
83
82
/// The leading widget for the headerbar
84
83
final List <Widget > start;
@@ -112,19 +111,13 @@ class AdwHeaderBar extends StatefulWidget {
112
111
}
113
112
114
113
class _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 ;
119
115
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 );
128
121
129
122
@override
130
123
void initState () {
@@ -138,10 +131,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
138
131
(e) => e
139
132
.split (',' )
140
133
.where (
141
- (element) =>
142
- element == 'close' ||
143
- element == 'maximize' ||
144
- element == 'minimize' ,
134
+ (element) => element == 'close' || element == 'maximize' || element == 'minimize' ,
145
135
)
146
136
.join (',' ),
147
137
);
@@ -156,8 +146,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
156
146
157
147
WidgetsBinding .instance.addPostFrameCallback ((_) async {
158
148
try {
159
- final buttonLayout =
160
- await schema.get ('button-layout' ) as DBusString ? ;
149
+ final buttonLayout = await schema.get ('button-layout' ) as DBusString ? ;
161
150
if (buttonLayout != null ) {
162
151
updateSep (buttonLayout.value);
163
152
}
@@ -187,9 +176,7 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
187
176
alignment: Alignment .topCenter,
188
177
child: Container (
189
178
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 ,
193
180
border: ! widget.style.isTransparent
194
181
? Border (
195
182
bottom: BorderSide (color: context.borderColor),
@@ -215,15 +202,11 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
215
202
leading: Row (
216
203
mainAxisSize: MainAxisSize .min,
217
204
children: [
218
- if (hasWindowControls &&
219
- sep != null &&
220
- sep[0 ].split (',' ).isNotEmpty) ...[
205
+ if (hasWindowControls && sep != null && sep[0 ].split (',' ).isNotEmpty) ...[
221
206
SizedBox (width: widget.style.titlebarSpace),
222
207
for (var i in sep[0 ].split (',' ))
223
208
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),
227
210
],
228
211
...widget.start.map (
229
212
(e) => Padding (
@@ -243,15 +226,11 @@ class _AdwHeaderBarState extends State<AdwHeaderBar> {
243
226
child: e,
244
227
),
245
228
),
246
- if (hasWindowControls &&
247
- sep != null &&
248
- sep[1 ].split (',' ).isNotEmpty) ...[
229
+ if (hasWindowControls && sep != null && sep[1 ].split (',' ).isNotEmpty) ...[
249
230
SizedBox (width: widget.style.titlebarSpace),
250
231
for (var i in sep[1 ].split (',' ))
251
232
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),
255
234
],
256
235
],
257
236
),
0 commit comments