Unverified Commit 44f54033 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `SliverAppBar.large` and `SliverAppBar.medium` do not use `foregroundColor` (#118322)

parent f8628b5c
...@@ -1652,6 +1652,7 @@ class SliverAppBar extends StatefulWidget { ...@@ -1652,6 +1652,7 @@ class SliverAppBar extends StatefulWidget {
actions: actions, actions: actions,
flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace( flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace(
title: title, title: title,
foregroundColor: foregroundColor,
variant: _ScrollUnderFlexibleVariant.medium, variant: _ScrollUnderFlexibleVariant.medium,
centerCollapsedTitle: centerTitle, centerCollapsedTitle: centerTitle,
primary: primary, primary: primary,
...@@ -1753,6 +1754,7 @@ class SliverAppBar extends StatefulWidget { ...@@ -1753,6 +1754,7 @@ class SliverAppBar extends StatefulWidget {
actions: actions, actions: actions,
flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace( flexibleSpace: flexibleSpace ?? _ScrollUnderFlexibleSpace(
title: title, title: title,
foregroundColor: foregroundColor,
variant: _ScrollUnderFlexibleVariant.large, variant: _ScrollUnderFlexibleVariant.large,
centerCollapsedTitle: centerTitle, centerCollapsedTitle: centerTitle,
primary: primary, primary: primary,
...@@ -2227,12 +2229,14 @@ enum _ScrollUnderFlexibleVariant { medium, large } ...@@ -2227,12 +2229,14 @@ enum _ScrollUnderFlexibleVariant { medium, large }
class _ScrollUnderFlexibleSpace extends StatelessWidget { class _ScrollUnderFlexibleSpace extends StatelessWidget {
const _ScrollUnderFlexibleSpace({ const _ScrollUnderFlexibleSpace({
this.title, this.title,
this.foregroundColor,
required this.variant, required this.variant,
this.centerCollapsedTitle, this.centerCollapsedTitle,
this.primary = true, this.primary = true,
}); });
final Widget? title; final Widget? title;
final Color? foregroundColor;
final _ScrollUnderFlexibleVariant variant; final _ScrollUnderFlexibleVariant variant;
final bool? centerCollapsedTitle; final bool? centerCollapsedTitle;
final bool primary; final bool primary;
...@@ -2240,6 +2244,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget { ...@@ -2240,6 +2244,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
late final ThemeData theme = Theme.of(context); late final ThemeData theme = Theme.of(context);
late final AppBarTheme appBarTheme = AppBarTheme.of(context);
final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!; final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!;
final double topPadding = primary ? MediaQuery.viewPaddingOf(context).top : 0; final double topPadding = primary ? MediaQuery.viewPaddingOf(context).top : 0;
final double collapsedHeight = settings.minExtent - topPadding; final double collapsedHeight = settings.minExtent - topPadding;
...@@ -2259,13 +2264,13 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget { ...@@ -2259,13 +2264,13 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
if (title != null) { if (title != null) {
collapsedTitle = config.collapsedTextStyle != null collapsedTitle = config.collapsedTextStyle != null
? DefaultTextStyle( ? DefaultTextStyle(
style: config.collapsedTextStyle!, style: config.collapsedTextStyle!.copyWith(color: foregroundColor ?? appBarTheme.foregroundColor),
child: title!, child: title!,
) )
: title; : title;
expandedTitle = config.expandedTextStyle != null expandedTitle = config.expandedTextStyle != null
? DefaultTextStyle( ? DefaultTextStyle(
style: config.expandedTextStyle!, style: config.expandedTextStyle!.copyWith(color: foregroundColor ?? appBarTheme.foregroundColor),
child: title!, child: title!,
) )
: title; : title;
...@@ -2286,9 +2291,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget { ...@@ -2286,9 +2291,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
return true; return true;
} }
} }
centerTitle = centerCollapsedTitle centerTitle = centerCollapsedTitle ?? appBarTheme.centerTitle ?? platformCenter();
?? theme.appBarTheme.centerTitle
?? platformCenter();
} }
final bool isCollapsed = settings.isScrolledUnder ?? false; final bool isCollapsed = settings.isScrolledUnder ?? false;
...@@ -2307,7 +2310,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget { ...@@ -2307,7 +2310,7 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
alignment: centerTitle alignment: centerTitle
? Alignment.center ? Alignment.center
: AlignmentDirectional.centerStart, : AlignmentDirectional.centerStart,
child: collapsedTitle child: collapsedTitle,
), ),
), ),
), ),
......
...@@ -574,6 +574,78 @@ void main() { ...@@ -574,6 +574,78 @@ void main() {
expect(navToolbar.middleSpacing, 40); expect(navToolbar.middleSpacing, 40);
}); });
testWidgets("SliverAppBar.medium's title uses AppBarTheme.foregroundColor", (WidgetTester tester) async {
const Color foregroundColor = Color(0xff00ff00);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(appBarTheme: const AppBarTheme(foregroundColor: foregroundColor)),
home: CustomScrollView(
slivers: <Widget>[
SliverAppBar.medium(
title: const Text('Medium Title'),
),
],
),
));
final RichText text = tester.firstWidget(find.byType(RichText));
expect(text.text.style!.color, foregroundColor);
});
testWidgets(
"SliverAppBar.medium's foregroundColor takes priority over AppBarTheme.foregroundColor", (WidgetTester tester) async {
const Color foregroundColor = Color(0xff00ff00);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(appBarTheme: const AppBarTheme(foregroundColor: Color(0xffff0000))),
home: CustomScrollView(
slivers: <Widget>[
SliverAppBar.medium(
foregroundColor: foregroundColor,
title: const Text('Medium Title'),
),
],
),
));
final RichText text = tester.firstWidget(find.byType(RichText));
expect(text.text.style!.color, foregroundColor);
});
testWidgets("SliverAppBar.large's title uses AppBarTheme.foregroundColor", (WidgetTester tester) async {
const Color foregroundColor = Color(0xff00ff00);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(appBarTheme: const AppBarTheme(foregroundColor: foregroundColor)),
home: CustomScrollView(
slivers: <Widget>[
SliverAppBar.large(
title: const Text('Large Title'),
),
],
),
));
final RichText text = tester.firstWidget(find.byType(RichText));
expect(text.text.style!.color, foregroundColor);
});
testWidgets(
"SliverAppBar.large's foregroundColor takes priority over AppBarTheme.foregroundColor", (WidgetTester tester) async {
const Color foregroundColor = Color(0xff00ff00);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(appBarTheme: const AppBarTheme(foregroundColor: Color(0xffff0000))),
home: CustomScrollView(
slivers: <Widget>[
SliverAppBar.large(
foregroundColor: foregroundColor,
title: const Text('Large Title'),
),
],
),
));
final RichText text = tester.firstWidget(find.byType(RichText));
expect(text.text.style!.color, foregroundColor);
});
testWidgets('Default AppBarTheme debugFillProperties', (WidgetTester tester) async { testWidgets('Default AppBarTheme debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const AppBarTheme().debugFillProperties(builder); const AppBarTheme().debugFillProperties(builder);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment