Skip to content

Search view expands to full screen on device rotation - #186537

Closed
elliette wants to merge 7 commits into
flutter:masterfrom
elliette:issue-186154-fix
Closed

elliette wants to merge 7 commits into
flutter:masterfrom
elliette:issue-186154-fix

Conversation

@elliette

@elliette elliette commented May 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #186154

The search anchor overlay now expands to fill the entire screen when the device is rotated and isFullScreen is true.
For non-mobile devices, the open search anchor overlay is similarly resized when the the device size is changed.

Previously we were calculating the search view's max width whenever the search view's route was pushed/popped. Switched to using the constraints provided by LayoutBuilder so that we can recalculate the view's max width during the layout phase when the device is rotated.

Before

Screenshot 2026-05-13 at 4 29 34 PM

After

Screenshot 2026-05-14 at 10 15 56 AM

Pre-launch Checklist

@elliette
elliette requested a review from QuncCccccc May 14, 2026 17:17
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 14, 2026
@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels May 14, 2026

@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 modifies the SearchAnchor component to ensure the search view correctly adapts to screen rotation by removing the viewMaxWidth parameter and utilizing a LayoutBuilder for dynamic constraints. It also includes a new regression test to verify full-screen expansion. Review feedback suggests that the LayoutBuilder is redundant because the view's dimensions are already updated via existing lifecycle methods, and recommends simplifying the widget tree and constraint logic to enhance readability and performance.

Comment thread packages/flutter/lib/src/material/search_anchor.dart
@elliette

Copy link
Copy Markdown
Member Author

Note: Review with "hide whitespace" 😄

Comment thread packages/flutter/lib/src/material/search_anchor.dart Outdated
Comment thread packages/flutter/lib/src/material/search_anchor.dart
@github-actions github-actions Bot removed the CICD Run CI/CD label May 15, 2026
@QuncCccccc QuncCccccc added the CICD Run CI/CD label May 15, 2026
QuncCccccc
QuncCccccc previously approved these changes May 15, 2026

@QuncCccccc QuncCccccc 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.

LGTM! Thanks! Once all tests pass, we can mark this as draft and move it over to material_ui package later:)!

@Zekfad

Zekfad commented May 17, 2026

Copy link
Copy Markdown

I believe _SearchAnchorState#_screenSize is incorrectly using screen size (mediaquery) instead of using size of surrounding navigator.

Please check if this example (dynamically changing navigator height) works well with proposed changes:

test.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue.shade100),
      ),
      home: Scaffold(
        appBar: AppBar(title: const Text('DraggableScrollableSheet Sample')),
        body: const DraggableScrollableSheetExample(),
      ),
    );
  }
}

class DraggableScrollableSheetExample extends StatefulWidget {
  const DraggableScrollableSheetExample({super.key});

  @override
  State<DraggableScrollableSheetExample> createState() =>
      _DraggableScrollableSheetExampleState();
}

class _DraggableScrollableSheetExampleState
    extends State<DraggableScrollableSheetExample> {
  double _dragPosition = 0.5;
  late double _sheetPosition = _dragPosition;
  final minChildSize = 0.25;
  final maxChildSize = 1.0;

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;

    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        final double viewHeight = constraints.maxHeight;

        return DraggableScrollableSheet(
          initialChildSize: _sheetPosition,
          builder: (BuildContext context, ScrollController scrollController) {
            return ColoredBox(
              color: colorScheme.primary,
              child: Column(
                children: <Widget>[
                  if (_isOnDesktopAndWeb)
                    Grabber(
                      onVerticalDragUpdate: (DragUpdateDetails details) {
                        setState(() {
                          _dragPosition -= details.delta.dy / viewHeight;
                          _sheetPosition = _dragPosition.clamp(
                            minChildSize,
                            maxChildSize,
                          );
                        });
                      },
                    ),
                  Flexible(
                    child: Navigator(
                      onGenerateRoute: (settings) => MaterialPageRoute(
                        builder: (context) => Scaffold(
                          body: SearchAnchor.bar(
                            isFullScreen: true,
                            suggestionsBuilder: (context, controller) => [
                              for (var i = 0; i < 10; i++)
                                ListTile(title: Text('Test $i')),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            );
          },
        );
      },
    );
  }

  bool get _isOnDesktopAndWeb =>
      kIsWeb ||
      switch (defaultTargetPlatform) {
        TargetPlatform.macOS ||
        TargetPlatform.linux ||
        TargetPlatform.windows => true,
        TargetPlatform.android ||
        TargetPlatform.iOS ||
        TargetPlatform.fuchsia => false,
      };
}

class Grabber extends StatelessWidget {
  const Grabber({super.key, required this.onVerticalDragUpdate});

  final ValueChanged<DragUpdateDetails> onVerticalDragUpdate;

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;

    return GestureDetector(
      onVerticalDragUpdate: onVerticalDragUpdate,
      child: Container(
        width: double.infinity,
        color: colorScheme.onSurface,
        child: Align(
          alignment: Alignment.topCenter,
          child: Container(
            margin: const EdgeInsets.symmetric(vertical: 8.0),
            width: 32.0,
            height: 4.0,
            decoration: BoxDecoration(
              color: colorScheme.surfaceContainerHighest,
              borderRadius: BorderRadius.circular(8.0),
            ),
          ),
        ),
      ),
    );
  }
}

@elliette

Copy link
Copy Markdown
Member Author

Hi @Zekfad - that sounds like a different issue than what this PR is addressing. Please file an issue for the above so that it can be tracked. Thanks!

@elliette
elliette force-pushed the issue-186154-fix branch from 45eaacb to 0399dca Compare May 18, 2026 17:10
@github-actions github-actions Bot removed the CICD Run CI/CD label May 18, 2026
@Zekfad

Zekfad commented May 18, 2026 •

Copy link
Copy Markdown

Thank you for your reply.
Then I believe this PR would not resolve #186154, as rotating screen is not the root cause, but only a single most visible side effect on mobile platform; on desktop(/web) resizing window will cause same the issue as in provided example above.
Mentioned issue specifically points to issue with search view size out of synth with it's navigator size and rotating screen is one of reproduction methods.

Should we unlink this PR from #186154, or should I file separate issue anyway, maybe then we need to clarify 186154?

@elliette elliette added the CICD Run CI/CD label May 18, 2026
@elliette

Copy link
Copy Markdown
Member Author

Hi @Zekfad - this PR also fixes the resizing window issue described in #186154. For other issues, please file a bug. Thank you!

@QuncCccccc

Copy link
Copy Markdown
Contributor

on desktop(/web) resizing window will cause same the issue as in provided example above.

I think we also fix the window resizing. This is the example you provdied.

Screen.Recording.2026-05-18.at.12.27.29.PM.mov

@elliette

Copy link
Copy Markdown
Member Author

With the latest commit, the code sample in #186537 (comment) should also be working correctly.

May-18-2026 14-39-35

@elliette elliette added the CICD Run CI/CD label May 18, 2026
@Zekfad

Zekfad commented May 18, 2026

Copy link
Copy Markdown

@QuncCccccc, @elliette thank you very much for your time to provide demo videos and fix for the edge case as well!
Will wait for future release when this will land.

Comment thread packages/flutter/test/material/search_anchor_test.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026
@elliette elliette added the CICD Run CI/CD label May 19, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026

@QuncCccccc QuncCccccc 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.

LGTM. Thanks!

child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: minWidth,
maxWidth: widget.showFullScreenView

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.

NICE catch:)!

@elliette
elliette force-pushed the issue-186154-fix branch from ba10bb8 to aba3d45 Compare May 19, 2026 21:32
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 19, 2026
@QuncCccccc QuncCccccc added the waiting for code freeze This PR is waiting for a code freeze to resolve. label May 20, 2026
@QuncCccccc

Copy link
Copy Markdown
Contributor

Seems this PR is ready to go🥳! Since we are waiting for decoupling, I added a "waiting for code freeze" label above and converted this PR to draft so later we'll move the change to material_ui package when it's ready!

@QuncCccccc
QuncCccccc marked this pull request as draft May 20, 2026 21:01
@Piinks Piinks added the Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. label Jun 24, 2026
@Piinks

Piinks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I've marked this PR as not ready to port to flutter/packages yet.
We'll provide instructions to move this change over to material_ui/cupertino_ui once ready to receive PRs. Thank you!

auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 20, 2026
…rt size changes (#12466)

**Port over flutter/flutter#186537 from flutter/flutter.**

Fixes flutter/flutter#186154

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot 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.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
@elliette

Copy link
Copy Markdown
Member Author

This PR was ported to package:material_ui in flutter/packages#12466, therefore closing.

@elliette elliette closed this Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages waiting for code freeze This PR is waiting for a code freeze to resolve.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search View doesn't update size on navigator resize

5 participants