builder gets executed with AnimationStyle.noAnimation (#156982)

Changed the if-statement nesting, so builder gets executed with AnimationStyle.noAnimation.

Pre-launch Checklist

Issue: https://github.com/flutter/flutter/issues/156959

[✅ ] I read the [Contributor Guide](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) and followed the process outlined there for submitting PRs.
[ ✅] I read the [Tree Hygiene](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md) wiki page, which explains my responsibilities.
[ ✅] I read and followed the [Flutter Style Guide](https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md), including [Features we expect every widget to implement](https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement).
[ ✅] I signed the [CLA](https://cla.developers.google.com/).
[ ✅] I listed at least one issue that this PR fixes in the description above.
I updated/added relevant documentation (doc comments with ///).
I added new tests to check the change I am making, or this PR is [test-exempt](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests).
I followed the [breaking change policy](https://github.com/flutter/flutter/blob/main/docs/contributing/Treehygiene.md#handling-breaking-changes) and added [Data Driven Fixes](https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md) where supported.
[✅ ] All existing and new tests are passing.
This commit is contained in:
Lurchfresser 2024-10-17 19:04:07 +02:00 committed by GitHub
parent 230cba2331
commit 5ce3ae0241
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 18 deletions

View File

@ -968,25 +968,25 @@ class _MaterialAppState extends State<MaterialApp> {
Widget childWidget = child ?? const SizedBox.shrink();
if (widget.builder != null) {
childWidget = Builder(
builder: (BuildContext context) {
// Why are we surrounding a builder with a builder?
//
// The widget.builder may contain code that invokes
// Theme.of(), which should return the theme we selected
// above in AnimatedTheme. However, if we invoke
// widget.builder() directly as the child of AnimatedTheme
// then there is no BuildContext separating them, the
// widget.builder() will not find the theme. Therefore, we
// surround widget.builder with yet another builder so that
// a context separates them and Theme.of() correctly
// resolves to the theme we passed to AnimatedTheme.
return widget.builder!(context, child);
},
);
}
if (widget.themeAnimationStyle != AnimationStyle.noAnimation) {
if (widget.builder != null) {
childWidget = Builder(
builder: (BuildContext context) {
// Why are we surrounding a builder with a builder?
//
// The widget.builder may contain code that invokes
// Theme.of(), which should return the theme we selected
// above in AnimatedTheme. However, if we invoke
// widget.builder() directly as the child of AnimatedTheme
// then there is no Context separating them, and the
// widget.builder() will not find the theme. Therefore, we
// surround widget.builder with yet another builder so that
// a context separates them and Theme.of() correctly
// resolves to the theme we passed to AnimatedTheme.
return widget.builder!(context, child);
},
);
}
childWidget = AnimatedTheme(
data: theme,
duration: widget.themeAnimationStyle?.duration ?? widget.themeAnimationDuration,

View File

@ -1662,6 +1662,22 @@ void main() {
expect(tester.getSize(find.byType(MaterialApp)), const Size(123, 456));
});
// Regression test for https://github.com/flutter/flutter/issues/156959.
testWidgets(
'MaterialApp with builder works when themeAnimationStyle is AnimationStyle.noAnimation',
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
themeAnimationStyle: AnimationStyle.noAnimation,
builder: (BuildContext context, Widget? child) {
return const Text('Works');
},
),
);
expect(find.text('Works'), findsOne);
},
);
}
class MockScrollBehavior extends ScrollBehavior {