Repository navigation
Conversation
…eserve MaterialBasedCupertinoThemeData Only look up InheritedCupertinoTheme in Theme.of(context) when no Material _InheritedTheme ancestor is present, use const NoDefaultCupertinoThemeData() when ThemeData.cupertinoOverrideTheme is null, and return the underlying Material ThemeData from CupertinoBasedMaterialThemeData when given a MaterialBasedCupertinoThemeData. This avoids an unnecessary InheritedElement dependency on every Theme.of(context) call and allows Dart TFA to tree-shake ColorScheme.fromSeed and package:material_color_utilities (-44.2 KB raw Wasm with --source-maps / -35.4 KB without --source-maps, and -18.5 KB code section across 166 functions on slide_puzzle) when ColorScheme.fromSeed is unused.
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes theme lookups and enables better tree-shaking. Specifically, it avoids looking up InheritedCupertinoTheme in Theme.of when a Material Theme ancestor is already present. It also updates MaterialBasedCupertinoThemeData to use NoDefaultCupertinoThemeData as a fallback, and modifies CupertinoBasedMaterialThemeData to preserve the underlying ThemeData when the provided theme is a MaterialBasedCupertinoThemeData. Corresponding unit tests and a changelog entry have been added. There are no review comments, and I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid looking up
InheritedCupertinoThemeon everyTheme.of(context)call when a Material_InheritedThemeancestor is already present, and break theTheme.build->MaterialBasedCupertinoThemeData->Theme.of->CupertinoBasedMaterialThemeData->ColorScheme.fromSeedretention cycle so Dart TFA can tree-shakeColorScheme.fromSeedandpackage:material_color_utilitieswhen unused.Theme.of(context)unconditionally calledcontext.dependOnInheritedWidgetOfExactType<InheritedCupertinoTheme>()before checkinginheritedTheme != null, registering a redundantInheritedElementdependency on every widget callingTheme.of(context)even when a MaterialThemeancestor was present.Theme.buildwraps every MaterialThemeinCupertinoTheme(data: MaterialBasedCupertinoThemeData(...)), andMaterialBasedCupertinoThemeDataevaluated(materialTheme.cupertinoOverrideTheme ?? const CupertinoThemeData()).noDefault(), instantiatingconst CupertinoThemeData()in every Material app.InheritedCupertinoThemeandCupertinoThemeDatawere always instantiated, Dart Type Flow Analysis (TFA) could not eliminate theCupertinoBasedMaterialThemeDatafallback branch inTheme.of(context), which callsColorScheme.fromSeedand retains all146CAM16/HCT solver functions inpackage:material_color_utilitieseven in apps that never useColorScheme.fromSeed.InheritedCupertinoThemeinTheme.of(context)wheninheritedTheme == null.(materialTheme.cupertinoOverrideTheme ?? const CupertinoThemeData()).noDefault()withmaterialTheme.cupertinoOverrideTheme?.noDefault() ?? const NoDefaultCupertinoThemeData()inMaterialBasedCupertinoThemeData.themeData._materialThemefromCupertinoBasedMaterialThemeDatawhenthemeDatais aMaterialBasedCupertinoThemeData.slide_puzzlewithflutter build web --wasm --no-strip-wasm --source-maps):.wasmsize:2,497,700 B->2,453,498 B(-44,202 B/-1.77%;-35,403 B/-1.42%without--source-maps)1,003,395 B->984,868 B(-18,527 B/-1.85%,-166functions)Theme.ofcompiled function size:1,633 B->361 B(-1,272 B/-77.89%)package:material_color_utilitiesretained code:17,096 B(146functions) ->24 B(2equality stubs,-99.86%)Part of flutter/flutter#188444
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2