perf(mediaquery): use scoped accessors (sizeOf, paddingOf, etc.)
This commit is contained in:
+2
-2
@@ -1100,13 +1100,13 @@ class _SetupScreenState extends State<SetupScreen> {
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: MediaQuery.of(context).size.height * 0.5 - 170,
|
||||
bottom: MediaQuery.sizeOf(context).height * 0.5 - 170,
|
||||
child: _buildStatusText(context),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: MediaQuery.of(context).size.height * 0.5 + 180,
|
||||
top: MediaQuery.sizeOf(context).height * 0.5 + 180,
|
||||
child: Center(
|
||||
child: _serverStatus.isEmpty
|
||||
? const SizedBox(
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ class _VideoState extends State<Video> {
|
||||
|
||||
final position = renderBox.localToGlobal(Offset.zero);
|
||||
final size = renderBox.size;
|
||||
final dpr = MediaQuery.of(context).devicePixelRatio;
|
||||
final dpr = MediaQuery.devicePixelRatioOf(context);
|
||||
|
||||
final newRect = Rect.fromLTWH(position.dx, position.dy, size.width, size.height);
|
||||
|
||||
|
||||
@@ -870,7 +870,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
}
|
||||
|
||||
Widget _buildOverlaidAppBar() {
|
||||
final statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
final statusBarHeight = MediaQuery.paddingOf(context).top;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
@@ -1059,7 +1059,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
final showServerNameOnHubs = context.watch<SettingsProvider>().showServerNameOnHubs;
|
||||
final duplicateHubTitles = _getDuplicateHubTitles();
|
||||
|
||||
final bottomPadding = MediaQuery.of(context).padding.bottom;
|
||||
final bottomPadding = MediaQuery.paddingOf(context).bottom;
|
||||
return Material(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Stack(
|
||||
@@ -1075,7 +1075,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
}
|
||||
// Add top padding when hero is not shown
|
||||
return SliverToBoxAdapter(
|
||||
child: SizedBox(height: kToolbarHeight + MediaQuery.of(context).padding.top + 16),
|
||||
child: SizedBox(height: kToolbarHeight + MediaQuery.paddingOf(context).top + 16),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -1201,7 +1201,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
}
|
||||
|
||||
Widget _buildHeroSection() {
|
||||
final statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
final statusBarHeight = MediaQuery.paddingOf(context).top;
|
||||
final useSideNav = PlatformDetector.shouldUseSideNavigation(context);
|
||||
final heroHeight = useSideNav ? MediaQuery.sizeOf(context).height * 0.75 : 500 + statusBarHeight;
|
||||
return SliverToBoxAdapter(
|
||||
@@ -1373,14 +1373,14 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
if (heroClient == null) {
|
||||
return ColoredBox(color: Theme.of(context).colorScheme.surfaceContainerHighest);
|
||||
}
|
||||
final mediaQuery = MediaQuery.of(context);
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
final dpr = PlexImageHelper.effectiveDevicePixelRatio(context);
|
||||
final containerAspect = screenWidth / heroHeight;
|
||||
final imageUrl = PlexImageHelper.getOptimizedImageUrl(
|
||||
client: heroClient,
|
||||
thumbPath: heroItem.heroArt(containerAspectRatio: containerAspect) ?? heroItem.grandparentArt,
|
||||
maxWidth: mediaQuery.size.width,
|
||||
maxHeight: mediaQuery.size.height * 0.7,
|
||||
maxWidth: size.width,
|
||||
maxHeight: size.height * 0.7,
|
||||
devicePixelRatio: dpr,
|
||||
imageType: ImageType.art,
|
||||
);
|
||||
|
||||
@@ -2471,13 +2471,13 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
|
||||
// Online - use network image
|
||||
final client = _getClientForMetadata(context);
|
||||
final mediaQuery = MediaQuery.of(context);
|
||||
final mqSize = MediaQuery.sizeOf(context);
|
||||
final dpr = PlexImageHelper.effectiveDevicePixelRatio(context);
|
||||
final imageUrl = PlexImageHelper.getOptimizedImageUrl(
|
||||
client: client,
|
||||
thumbPath: heroArtPath,
|
||||
maxWidth: mediaQuery.size.width,
|
||||
maxHeight: mediaQuery.size.height * 0.6,
|
||||
maxWidth: mqSize.width,
|
||||
maxHeight: mqSize.height * 0.6,
|
||||
devicePixelRatio: dpr,
|
||||
imageType: ImageType.art,
|
||||
);
|
||||
@@ -2829,7 +2829,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom)),
|
||||
SliverPadding(padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom)),
|
||||
],
|
||||
),
|
||||
// Sticky top bar with fading background
|
||||
@@ -2848,7 +2848,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).padding.top + 58,
|
||||
height: MediaQuery.paddingOf(context).top + 58,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
|
||||
@@ -10,7 +10,7 @@ class GridSizeCalculator {
|
||||
/// Calculates the maximum cross-axis extent for grid items based on screen size and density.
|
||||
/// [density] is an int 1–5 (1 = most compact, 5 = most comfortable).
|
||||
static double getMaxCrossAxisExtent(BuildContext context, int density) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final f = LibraryDensity.factor(density);
|
||||
|
||||
if (PlatformDetector.isTV()) return _lerp(120, 220, f);
|
||||
@@ -22,7 +22,7 @@ class GridSizeCalculator {
|
||||
/// Calculates the max cross-axis extent accounting for outer padding.
|
||||
/// [density] is an int 1–5.
|
||||
static double getMaxCrossAxisExtentWithPadding(BuildContext context, int density, double horizontalPadding) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final availableWidth = screenWidth - horizontalPadding;
|
||||
final f = LibraryDensity.factor(density);
|
||||
|
||||
|
||||
@@ -131,10 +131,9 @@ class PlatformDetector {
|
||||
/// Detects if the device is likely a tablet based on screen size
|
||||
/// Uses diagonal screen size to determine if device is a tablet
|
||||
static bool isTablet(BuildContext context) {
|
||||
final data = MediaQuery.of(context);
|
||||
final size = data.size;
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
final diagonal = sqrt(size.width * size.width + size.height * size.height);
|
||||
final devicePixelRatio = data.devicePixelRatio;
|
||||
final devicePixelRatio = MediaQuery.devicePixelRatioOf(context);
|
||||
|
||||
// Convert diagonal from logical pixels to inches (assuming 160 DPI as baseline)
|
||||
final diagonalInches = diagonal / (devicePixelRatio * 160 / 2.54);
|
||||
|
||||
@@ -43,7 +43,7 @@ class PlexImageHelper {
|
||||
/// the platform-reported DPR doesn't reflect the true physical density
|
||||
/// (common on Linux X11 with compositor scaling).
|
||||
static double effectiveDevicePixelRatio(BuildContext context) {
|
||||
final reportedDpr = MediaQuery.of(context).devicePixelRatio;
|
||||
final reportedDpr = MediaQuery.devicePixelRatioOf(context);
|
||||
double dpr;
|
||||
try {
|
||||
final displayWidth = View.of(context).display.size.width;
|
||||
|
||||
@@ -1702,7 +1702,7 @@ class _FocusablePopupMenuState extends State<_FocusablePopupMenu> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final screenSize = MediaQuery.sizeOf(context);
|
||||
const menuWidth = 220.0;
|
||||
|
||||
// Clamp menu position to stay within screen bounds
|
||||
|
||||
@@ -126,7 +126,7 @@ class OverlaySheetController {
|
||||
final effectiveConstraints =
|
||||
constraints ??
|
||||
() {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
final isDesktop = size.width > 600;
|
||||
return BoxConstraints(
|
||||
maxWidth: isDesktop ? 700 : double.infinity,
|
||||
@@ -496,7 +496,7 @@ class _OverlaySheetHostState extends State<OverlaySheetHost> with SingleTickerPr
|
||||
}
|
||||
|
||||
Widget _buildSheet(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
final isDesktop = size.width > 600;
|
||||
final isTop = _alignment.y < 0;
|
||||
final isTV = PlatformDetector.isTV();
|
||||
|
||||
@@ -73,7 +73,7 @@ class _ServerActivitiesButtonState extends State<ServerActivitiesButton> {
|
||||
if (renderBox == null) return;
|
||||
final buttonOffset = renderBox.localToGlobal(Offset.zero);
|
||||
final buttonSize = renderBox.size;
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final screenSize = MediaQuery.sizeOf(context);
|
||||
|
||||
final right = screenSize.width - (buttonOffset.dx + buttonSize.width);
|
||||
final top = buttonOffset.dy + buttonSize.height + 4;
|
||||
|
||||
@@ -390,7 +390,7 @@ class SideNavigationRailState extends State<SideNavigationRail> {
|
||||
|
||||
/// Calculate top padding for macOS traffic lights
|
||||
double _getTopPadding(BuildContext context) {
|
||||
double basePadding = MediaQuery.of(context).padding.top + 16;
|
||||
double basePadding = MediaQuery.paddingOf(context).top + 16;
|
||||
|
||||
// On macOS, add extra padding for traffic lights (when not fullscreen)
|
||||
if (Platform.isMacOS) {
|
||||
|
||||
@@ -440,7 +440,7 @@ class _MobileVideoControlsState extends State<MobileVideoControls> with SingleTi
|
||||
bool top = true,
|
||||
bool bottom = true,
|
||||
}) {
|
||||
final orientation = MediaQuery.of(context).orientation;
|
||||
final orientation = MediaQuery.orientationOf(context);
|
||||
final isPortrait = orientation == Orientation.portrait;
|
||||
|
||||
// Only apply SafeArea in portrait mode
|
||||
|
||||
Reference in New Issue
Block a user