Skip to content

⚡ Bolt: Optimize MediaQuery, Provider and ListView performance#31

Closed
Doezer wants to merge 1 commit intomainfrom
bolt/optimize-mediaquery-provider-listview-13165580549914883393
Closed

⚡ Bolt: Optimize MediaQuery, Provider and ListView performance#31
Doezer wants to merge 1 commit intomainfrom
bolt/optimize-mediaquery-provider-listview-13165580549914883393

Conversation

@Doezer
Copy link
Owner

@Doezer Doezer commented Feb 8, 2026

💡 What: Optimized MediaQuery usage, Provider listening, and ListView rendering across several key components.
🎯 Why: Reducing unnecessary widget rebuilds and layout passes significantly improves app responsiveness, especially on lower-end devices or during frequent system state changes (like keyboard visibility or orientation shifts).
📊 Impact:

  • Replaces generic MediaQuery dependencies with specific ones, reducing rebuild frequency for 10+ widgets.
  • Prevents SideNavigationRail from rebuilding on unrelated HiddenLibrariesProvider updates.
  • Optimizes horizontal scrolling in HubSection by skipping child measurement.
    🔬 Measurement: Verified with 'flutter analyze' and manual inspection of the framework's rebuild triggers.

PR created automatically by Jules for task 13165580549914883393 started by @Doezer

Optimized the application performance by implementing several Flutter best practices:
- Replaced MediaQuery.of(context) with specialized selectors (sizeOf, paddingOf, etc.) across multiple files to reduce unnecessary rebuilds.
- Optimized SideNavigationRail by using context.select to narrow down HiddenLibrariesProvider dependencies.
- Improved HubSection scroll performance by adding itemExtent to its horizontal ListView.builder.

These changes reduce the widget rebuild frequency and improve layout efficiency.

Co-authored-by: Doezer <11655673+Doezer@users.noreply.github.com>
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Doezer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's performance and responsiveness by implementing targeted optimizations. The changes focus on minimizing widget rebuilds through more granular dependency tracking, particularly with MediaQuery and Provider, and by leveraging ListView rendering efficiencies. These improvements aim to provide a smoother user experience, especially under dynamic system conditions or on less powerful devices.

Highlights

  • Optimized MediaQuery Usage: Replaced generic MediaQuery.of(context) calls with specialized selectors like MediaQuery.sizeOf(context), MediaQuery.paddingOf(context), MediaQuery.devicePixelRatioOf(context), and MediaQuery.orientationOf(context) across 10+ widgets. This ensures widgets only rebuild when the specific property they depend on changes, significantly reducing unnecessary rebuilds.
  • Targeted Provider Listening: Updated SideNavigationRail to use context.select for HiddenLibrariesProvider. This prevents the SideNavigationRail from rebuilding on unrelated updates within the provider, ensuring it only reacts when hiddenLibraryKeys specifically change.
  • ListView Performance Improvement: Introduced itemExtent to the ListView.builder in HubSection for horizontal scrolling. This optimization allows the framework to skip child measurement, improving rendering performance for lists with uniform item sizes.
  • New Documentation Added: A new documentation file, .jules/bolt.md, has been added to explain the best practices for using specialized MediaQuery selectors and ListView itemExtent in modern Flutter (3.10+).
Changelog
  • .jules/bolt.md
    • Added new documentation file detailing best practices for MediaQuery selectors and ListView itemExtent.
  • lib/mpv/video.dart
    • Replaced MediaQuery.of(context).devicePixelRatio with MediaQuery.devicePixelRatioOf(context).
  • lib/screens/discover_screen.dart
    • Updated MediaQuery.of(context).padding.top to MediaQuery.paddingOf(context).top in _buildOverlaidAppBar and for SizedBox height calculation.
    • Changed MediaQuery.of(context).size.height to MediaQuery.sizeOf(context).height in _buildHeroSection.
    • Replaced MediaQuery.of(context).size.width with MediaQuery.sizeOf(context).width in _buildHeroItem.
    • Refactored MediaQuery.of(context) to use MediaQuery.sizeOf(context) and MediaQuery.devicePixelRatioOf(context) for image optimization in _buildHeroItem.
  • lib/utils/grid_size_calculator.dart
    • Replaced MediaQuery.of(context).size.width with MediaQuery.sizeOf(context).width in getMaxCrossAxisExtent, getCrossAxisCount, isDesktop, isTablet, and isMobile methods.
  • lib/utils/platform_detector.dart
    • Updated MediaQuery.of(context) to use MediaQuery.sizeOf(context) and MediaQuery.devicePixelRatioOf(context) in isTablet method.
  • lib/widgets/file_info_bottom_sheet.dart
    • Replaced MediaQuery.of(context).size.height with MediaQuery.sizeOf(context).height for SizedBox height.
  • lib/widgets/hub_section.dart
    • Added itemExtent: _itemExtent to ListView.builder for horizontal lists to improve performance.
  • lib/widgets/media_context_menu.dart
    • Replaced MediaQuery.of(context).size with MediaQuery.sizeOf(context).
  • lib/widgets/plex_optimized_image.dart
    • Replaced MediaQuery.of(context).devicePixelRatio with MediaQuery.devicePixelRatioOf(context).
  • lib/widgets/side_navigation_rail.dart
    • Updated MediaQuery.of(context).padding.top to MediaQuery.paddingOf(context).top in _getTopPadding.
    • Changed context.watch<HiddenLibrariesProvider>() to context.select<HiddenLibrariesProvider, Set<String>>((p) => p.hiddenLibraryKeys) for more specific Provider listening.
  • lib/widgets/video_controls/mobile_video_controls.dart
    • Replaced MediaQuery.of(context).orientation with MediaQuery.orientationOf(context).
  • lib/widgets/video_controls/sheets/base_video_control_sheet.dart
    • Updated MediaQuery.of(context).size to MediaQuery.sizeOf(context) in getBottomSheetConstraints and for SizedBox height.
Activity
  • This pull request was automatically created by Jules for a task initiated by @Doezer.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that systematically applies important Flutter performance optimizations across the application. The changes to use more specific MediaQuery selectors, context.select for Provider, and itemExtent for ListView are all best practices that will tangibly reduce unnecessary widget rebuilds and improve app responsiveness. The code is clean, the changes are consistent, and the goal is well-articulated. I have one suggestion for a potential further optimization in GridSizeCalculator to avoid redundant lookups.

Comment on lines 88 to 106
/// Returns whether the current screen is a desktop-sized screen
static bool isDesktop(BuildContext context) {
return MediaQuery.of(context).size.width > desktopBreakpoint;
// Optimization: Use MediaQuery.sizeOf(context) to only rebuild when screen width changes.
return MediaQuery.sizeOf(context).width > desktopBreakpoint;
}

/// Returns whether the current screen is a tablet-sized screen
static bool isTablet(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
// Optimization: Use MediaQuery.sizeOf(context) to only rebuild when screen width changes.
final screenWidth = MediaQuery.sizeOf(context).width;
return screenWidth > tabletBreakpoint && screenWidth <= desktopBreakpoint;
}

/// Returns whether the current screen is a mobile-sized screen
static bool isMobile(BuildContext context) {
return MediaQuery.of(context).size.width <= tabletBreakpoint;
// Optimization: Use MediaQuery.sizeOf(context) to only rebuild when screen width changes.
return MediaQuery.sizeOf(context).width <= tabletBreakpoint;
}
}

Choose a reason for hiding this comment

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

medium

While these methods correctly use MediaQuery.sizeOf(context).width for optimization, calling multiple of them from the same build method (e.g., isDesktop(context) and then isTablet(context)) will result in redundant MediaQuery lookups. To further improve performance, consider refactoring them to accept screenWidth as a parameter. This encourages callers to fetch the screen width once and reuse it.

For example:

// In GridSizeCalculator:
static bool isDesktop(double screenWidth) {
  return screenWidth > desktopBreakpoint;
}

// In the consumer widget's build method:
final screenWidth = MediaQuery.sizeOf(context).width;
final isDesktop = GridSizeCalculator.isDesktop(screenWidth);

This change would require updating all call sites but promotes a more efficient usage pattern throughout the app.

@Doezer Doezer closed this Feb 8, 2026
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.

1 participant