Skip to content

Add dark mode to the Flutter blog - #13954

Open
conooi wants to merge 17 commits into
flutter:mainfrom
conooi:blog-dark-mode
Open

conooi wants to merge 17 commits into
flutter:mainfrom
conooi:blog-dark-mode

Conversation

@conooi

@conooi conooi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Adds dark mode support (Light, Dark, and Automatic) to the Flutter blog (flutter.dev/blog), matching the theme switcher experience on dart.dev and docs.flutter.dev:

  • Header theme switcher: Renders NestedThemeSwitcher in the flutter.dev header when viewing /blog pages and auto-closes the dropdown menu on selection.
  • Pre-paint theme initialization & persistence: Extracts shared themeInitScript and themeSyncBodyScript helpers in package:site_shared so both DashLayout and BlogLayout apply the stored localStorage['theme'] preference before first paint and stay in sync across browser back/forward navigation (pageshow), cross-tab storage events, and live OS prefers-color-scheme changes.
  • Scoped blog dark theme styles: Adds dark mode CSS custom properties, .opal dark syntax highlighting overrides, header/footer dark styling, and diagram/icon contrast safeguards (--site-diagram-wrap-bgColor, .light-mode-visible, .dark-mode-visible, .theme-icon) scoped to body.blog in _blog_page.scss without affecting other flutter.dev marketing pages.
  • Hydration optimization: Skips redundant .blog-card DOM class mutations in BlogCategories during initial hydration when the default all view is already server-rendered.

Fixes #13942

@conooi
conooi requested a review from parlough October 2, 2026 22:56
@conooi
conooi requested review from a team, abdallahshaban557 and sfshaza2 as code owners October 2, 2026 22:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a comprehensive dark mode theme system for the blog, introducing a NestedThemeSwitcher component, centralizing theme initialization and synchronization scripts, and updating layouts, components, and SCSS styles to support dark mode. Feedback on the changes highlights a style guide violation where unawaited calls in ThemeSwitcher.dispose should include explanatory comments.

Comment thread packages/site_shared/lib/components/layout/theme_switcher.dart Outdated
@flutter-website-bot

flutter-website-bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit ae56abb):

https://flutter-docs-prod--docs-pr13954-blog-dark-mode-97n6shd9.web.app

@flutter-website-bot

flutter-website-bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit ae56abb):

https://flutter-dev-230821--www-pr13954-blog-dark-mode-tcpu8yil.web.app

@parlough parlough self-assigned this Oct 5, 2026

@parlough parlough left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for exploring this @conooi!

Generally looks great and like a good direction, with most of my remaining concerns about generalizing the style updates so future updates and maintenance are easier. Perhaps the capability can be expanded in the future as well.

Let me know if you have any questions or if you'd prefer I tackle any of the suggestions. Thanks again :D

Comment thread packages/site_shared/lib/components/layout/theme_switcher.dart Outdated
Comment thread sites/www/lib/styles/pages/_blog_page.scss Outdated
Comment thread packages/site_shared/lib/src/utils/theme_script.dart Outdated
Comment thread sites/www/lib/src/layouts/blog_layout.dart Outdated
Comment thread sites/www/lib/src/layouts/default_layout.dart Outdated
Comment thread sites/www/lib/styles/pages/_blog_page.scss Outdated
Comment thread packages/site_shared/lib/components/layout/theme_switcher.dart Outdated
@conooi

conooi commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @parlough! I've updated the PR to address all of your feedback:

  • Consistent document.body theme classes & focused init script: Updated ThemeSwitcher and themeInitScript to only target document.body (matching docs.flutter.dev), removed themeSyncBodyScript and the duplicate JS event listeners, and filtered the storageEvent listener in ThemeSwitcher to the 'theme' key.
  • Layout cleanup: Moved themeInitScript into BlogLayout.leadingBodyElements, removed leadingHeadElements and the inline <style> tag, and added API doc comments to the DefaultLayout getters.
  • Generalized theme styles:
    • Extracted the #theme-switcher and .light-mode-visible / .dark-mode-visible styles into a dedicated lib/styles/components/_theme-switcher.scss file.
    • Updated the shared _header.scss and _footer.scss files to use the --site-* CSS variables and moved the body.dark-mode variable overrides to _vars.scss, removing all custom dark-mode header/footer overrides from _blog_page.scss.
  • Dark mode Flutter logo: Added flutter-logo-dark.svg (keeping the blue Flutter logomark with a white wordmark) for .dark-mode-visible in the header and footer so the icon mark doesn't turn solid white on dark backgrounds.

Ready for another look when you have a chance!

@conooi
conooi requested a review from parlough October 5, 2026 22:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces dark mode support across the websites by defining theme-specific CSS variables, adding a ThemeSwitcher component, and using an inline script to apply the saved theme preference before the page paints. It also refactors the blog card layout logic using a new BlogCardLayout enum, updates the header and footer to support dark-themed logos, and improves dropdown focus behavior. The review feedback highlights potential runtime TypeError risks in dropdown.dart when casting event targets directly to web.Element, and notes styling regressions in the footer where removing explicit link colors causes them to default to the global blue link color instead of inheriting the muted footer text color.

Comment thread packages/site_shared/lib/components/common/dropdown.dart
Comment thread packages/site_shared/lib/components/common/dropdown.dart
Comment thread sites/www/lib/styles/components/_footer.scss
Comment thread sites/www/lib/styles/components/_footer.scss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Dark mode to Blog - Like dart version

3 participants