Skip to content

[Android] MediaQuery.padding and MediaQuery.viewPadding incorrectly use device MediaQuery.size.height in floating window or split-screen mode #174269

@GiancarloCante

Description

@GiancarloCante

Environment

  • Device: Xiaomi Redmi Pad 2
  • OS: Android 15 (API 35) – HyperOS 2.0.202.0
  • Flutter version: 3.35.1

Steps to Reproduce

  1. Run the following minimal app:
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomePage());
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final mediaQuery = MediaQuery.of(context);
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(32),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Text('MediaQuery.size'),
              Text('${mediaQuery.size}'),
              Divider(),
              Text('MediaQuery.padding'),
              Text('${mediaQuery.padding}'),
              Divider(),
              Text('MediaQuery.viewPadding'),
              Text('${mediaQuery.viewPadding}'),
              Divider(),
              Text('MediaQuery'),
              Text('$mediaQuery'),
            ],
          ),
        ),
      ),
    );
  }
}
  1. Switch the app to floating window mode.
  2. Switch the app to split-screen mode.

Expected Results

  • MediaQuery.padding and MediaQuery.viewPadding should reflect the correct safe insets for the current window size (floating or split-screen).

Actual Results

Full Screen (works correctly):

MediaQuery.size: (1137.8, 711.1)
MediaQuery.padding: (0.0, 31.1, 0.0, 16.0)
MediaQuery.viewPadding: (0.0, 31.1, 0.0, 16.0)
Image

Floating Window (incorrect):

MediaQuery.size: (420.4, 750.2)
MediaQuery.padding: (0.0, 750.2, 0.0, 31.1)
MediaQuery.viewPadding: (0.0, 750.2, 0.0, 31.1)
Image

Split Screen (incorrect):

MediaQuery.size: (563.6, 711.1)
MediaQuery.padding: (0.0, 711.1, 0.0, 16.0)
MediaQuery.viewPadding: (0.0, 711.1, 0.0, 16.0)
Image

Impact

This unexpected behavior makes it impossible to correctly use the SafeArea widget in floating window or split-screen mode. Currently, any layout or calculation that depends on MediaQuery.padding (or viewPadding) produces incorrect results, since the values are based on the full device height instead of the actual window size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions