@@ -97,6 +97,8 @@ class ZeroAppBar extends StatelessWidget implements PreferredSizeWidget {
97
97
statusBarBrightness: adaptiveStyle.statusBarBrightness,
98
98
);
99
99
100
+ final _isNoLeading = ! automaticallyImplyLeading && leading == null ;
101
+
100
102
return Semantics (
101
103
container: true ,
102
104
child: AnnotatedRegion <SystemUiOverlayStyle >(
@@ -134,9 +136,19 @@ class ZeroAppBar extends StatelessWidget implements PreferredSizeWidget {
134
136
children: [
135
137
// Build leading
136
138
_Leading (
137
- auto: automaticallyImplyLeading,
139
+ automaticallyImplyLeading:
140
+ automaticallyImplyLeading,
138
141
leading: leading,
139
142
),
143
+
144
+ // Build spacing based on conditions
145
+ if (_isNoLeading)
146
+ const SizedBox (width: 16 )
147
+ else if (adaptiveStyle.centerTitle == true )
148
+ const SizedBox .shrink ()
149
+ else
150
+ const SizedBox (width: 32 ),
151
+
140
152
// Build title small size
141
153
Expanded (
142
154
child: size == ZeroAppBarSize .small
@@ -146,8 +158,18 @@ class ZeroAppBar extends StatelessWidget implements PreferredSizeWidget {
146
158
)
147
159
: const SizedBox .shrink (),
148
160
),
161
+
149
162
// Build actions
150
- Row (children: actions ?? [])
163
+ Row (
164
+ children: actions ??
165
+ (adaptiveStyle.centerTitle == true
166
+ ? [
167
+ SizedBox .square (
168
+ dimension:
169
+ _isNoLeading ? 16 : 48 )
170
+ ]
171
+ : []),
172
+ )
151
173
],
152
174
),
153
175
),
@@ -158,7 +180,9 @@ class ZeroAppBar extends StatelessWidget implements PreferredSizeWidget {
158
180
const Spacer (),
159
181
Padding (
160
182
padding: EdgeInsets .only (
161
- bottom: size == ZeroAppBarSize .large ? 20 : 16 ),
183
+ bottom: size == ZeroAppBarSize .large ? 20 : 16 ,
184
+ left: 16 ,
185
+ ),
162
186
child: _Title (style: adaptiveStyle, title: title),
163
187
),
164
188
],
@@ -202,10 +226,7 @@ class _Title extends StatelessWidget {
202
226
style: titleStyle,
203
227
maxLines: 1 ,
204
228
overflow: TextOverflow .ellipsis,
205
- child: Padding (
206
- padding: const EdgeInsets .only (left: 16 ),
207
- child: title ?? const SizedBox (),
208
- ),
229
+ child: title ?? const SizedBox .shrink (),
209
230
);
210
231
211
232
/// If centerTitle, title will be wrap with [Center] widget
@@ -216,19 +237,22 @@ class _Title extends StatelessWidget {
216
237
/// A widget for building leading of [ZeroAppBar]
217
238
class _Leading extends StatelessWidget {
218
239
const _Leading ({
219
- required this .auto ,
240
+ required this .automaticallyImplyLeading ,
220
241
required this .leading,
221
242
});
222
243
223
244
/// Set automatically leading or not
224
- final bool auto ;
245
+ final bool automaticallyImplyLeading ;
225
246
226
- /// Customize leading, if null and [auto ] is true leading will auto set
247
+ /// Customize leading, if null and [automaticallyImplyLeading ] is true leading will auto set
227
248
final Widget ? leading;
228
249
229
250
@override
230
251
Widget build (BuildContext context) {
231
- if (leading != null ) return leading ?? const SizedBox ();
252
+ if (automaticallyImplyLeading == false || leading != null ) {
253
+ return leading ?? const SizedBox .shrink ();
254
+ }
255
+
232
256
final scaffold = Scaffold .maybeOf (context);
233
257
final parentRoute = ModalRoute .of (context);
234
258
final hasDrawer = scaffold? .hasDrawer ?? false ;
@@ -253,11 +277,11 @@ class _Leading extends StatelessWidget {
253
277
onPressed: () {
254
278
Navigator .of (context).pop ();
255
279
},
256
- tooltip: localization.backButtonTooltip,
257
280
icon: const Icon (ZeroIcons .arrowLeft),
281
+ tooltip: localization.backButtonTooltip,
258
282
);
259
283
}
260
284
261
- return const SizedBox ();
285
+ return const SizedBox . shrink ();
262
286
}
263
287
}
0 commit comments