@@ -1528,13 +1528,16 @@ class SliverAppBar extends StatefulWidget {
1528
1528
key: key,
1529
1529
leading: leading,
1530
1530
automaticallyImplyLeading: automaticallyImplyLeading,
1531
- actions: actions,
1532
1531
flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace (
1532
+ hasLeading: leading != null ,
1533
1533
title: title,
1534
+ actions: actions,
1534
1535
foregroundColor: foregroundColor,
1535
1536
variant: _ScrollUnderFlexibleVariant .medium,
1536
1537
centerCollapsedTitle: centerTitle,
1537
1538
primary: primary,
1539
+ leadingWidth: leadingWidth,
1540
+ titleSpacing: titleSpacing,
1538
1541
),
1539
1542
bottom: bottom,
1540
1543
elevation: elevation,
@@ -1630,13 +1633,16 @@ class SliverAppBar extends StatefulWidget {
1630
1633
key: key,
1631
1634
leading: leading,
1632
1635
automaticallyImplyLeading: automaticallyImplyLeading,
1633
- actions: actions,
1634
1636
flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace (
1637
+ hasLeading: leading != null ,
1635
1638
title: title,
1639
+ actions: actions,
1636
1640
foregroundColor: foregroundColor,
1637
1641
variant: _ScrollUnderFlexibleVariant .large,
1638
1642
centerCollapsedTitle: centerTitle,
1639
1643
primary: primary,
1644
+ leadingWidth: leadingWidth,
1645
+ titleSpacing: titleSpacing,
1640
1646
),
1641
1647
bottom: bottom,
1642
1648
elevation: elevation,
@@ -2077,18 +2083,26 @@ enum _ScrollUnderFlexibleVariant { medium, large }
2077
2083
2078
2084
class _ScrollUnderFlexibleSpace extends StatelessWidget {
2079
2085
const _ScrollUnderFlexibleSpace ({
2086
+ required this .hasLeading,
2080
2087
this .title,
2088
+ this .actions,
2081
2089
this .foregroundColor,
2082
2090
required this .variant,
2083
2091
this .centerCollapsedTitle,
2084
2092
this .primary = true ,
2093
+ this .leadingWidth,
2094
+ this .titleSpacing,
2085
2095
});
2086
2096
2097
+ final bool hasLeading;
2087
2098
final Widget ? title;
2099
+ final List <Widget >? actions;
2088
2100
final Color ? foregroundColor;
2089
2101
final _ScrollUnderFlexibleVariant variant;
2090
2102
final bool ? centerCollapsedTitle;
2091
2103
final bool primary;
2104
+ final double ? leadingWidth;
2105
+ final double ? titleSpacing;
2092
2106
2093
2107
@override
2094
2108
Widget build (BuildContext context) {
@@ -2142,24 +2156,35 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
2142
2156
centerTitle = centerCollapsedTitle ?? appBarTheme.centerTitle ?? platformCenter ();
2143
2157
}
2144
2158
2159
+ EdgeInsetsGeometry effectiveCollapsedTitlePadding = EdgeInsets .zero;
2160
+ if (hasLeading && leadingWidth == null ) {
2161
+ effectiveCollapsedTitlePadding = centerTitle
2162
+ ? config.collapsedCenteredTitlePadding!
2163
+ : config.collapsedTitlePadding! ;
2164
+ } else if (hasLeading && leadingWidth != null ) {
2165
+ effectiveCollapsedTitlePadding = EdgeInsetsDirectional .only (start: leadingWidth! );
2166
+ }
2145
2167
final bool isCollapsed = settings.isScrolledUnder ?? false ;
2146
2168
return Column (
2147
2169
children: < Widget > [
2148
2170
Padding (
2149
2171
padding: EdgeInsets .only (top: topPadding),
2150
2172
child: Container (
2151
2173
height: collapsedHeight,
2152
- padding: centerTitle ? config.collapsedCenteredTitlePadding : config.collapsedTitlePadding,
2153
- child: AnimatedOpacity (
2154
- opacity: isCollapsed ? 1 : 0 ,
2155
- duration: const Duration (milliseconds: 500 ),
2156
- curve: const Cubic (0.2 , 0.0 , 0.0 , 1.0 ),
2157
- child: Align (
2158
- alignment: centerTitle
2159
- ? Alignment .center
2160
- : AlignmentDirectional .centerStart,
2174
+ padding: effectiveCollapsedTitlePadding,
2175
+ child: NavigationToolbar (
2176
+ centerMiddle: centerTitle,
2177
+ middleSpacing: titleSpacing ?? appBarTheme.titleSpacing ?? NavigationToolbar .kMiddleSpacing,
2178
+ middle: AnimatedOpacity (
2179
+ opacity: isCollapsed ? 1 : 0 ,
2180
+ duration: const Duration (milliseconds: 500 ),
2181
+ curve: const Cubic (0.2 , 0.0 , 0.0 , 1.0 ),
2161
2182
child: collapsedTitle,
2162
2183
),
2184
+ trailing: actions != null ? Row (
2185
+ mainAxisSize: MainAxisSize .min,
2186
+ children: actions! ,
2187
+ ) : null ,
2163
2188
),
2164
2189
),
2165
2190
),
@@ -2295,10 +2320,10 @@ class _MediumScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig {
2295
2320
_textTheme.headlineSmall? .apply (color: _colors.onSurface);
2296
2321
2297
2322
@override
2298
- EdgeInsetsGeometry ? get collapsedTitlePadding => const EdgeInsetsDirectional .fromSTEB ( 48 , 0 , 16 , 0 );
2323
+ EdgeInsetsGeometry ? get collapsedTitlePadding => const EdgeInsetsDirectional .only (start : 40 );
2299
2324
2300
2325
@override
2301
- EdgeInsetsGeometry ? get collapsedCenteredTitlePadding => const EdgeInsets . fromLTRB ( 16 , 0 , 16 , 0 );
2326
+ EdgeInsetsGeometry ? get collapsedCenteredTitlePadding => const EdgeInsetsDirectional . only (start : 40 );
2302
2327
2303
2328
@override
2304
2329
EdgeInsetsGeometry ? get expandedTitlePadding => const EdgeInsets .fromLTRB (16 , 0 , 16 , 20 );
@@ -2324,10 +2349,10 @@ class _LargeScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig {
2324
2349
_textTheme.headlineMedium? .apply (color: _colors.onSurface);
2325
2350
2326
2351
@override
2327
- EdgeInsetsGeometry ? get collapsedTitlePadding => const EdgeInsetsDirectional .fromSTEB ( 48 , 0 , 16 , 0 );
2352
+ EdgeInsetsGeometry ? get collapsedTitlePadding => const EdgeInsetsDirectional .only (start : 40 );
2328
2353
2329
2354
@override
2330
- EdgeInsetsGeometry ? get collapsedCenteredTitlePadding => const EdgeInsets . fromLTRB ( 16 , 0 , 16 , 0 );
2355
+ EdgeInsetsGeometry ? get collapsedCenteredTitlePadding => const EdgeInsetsDirectional . only (start : 40 );
2331
2356
2332
2357
@override
2333
2358
EdgeInsetsGeometry ? get expandedTitlePadding => const EdgeInsets .fromLTRB (16 , 0 , 16 , 28 );
0 commit comments