Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create SearchBar and SearchBarTheme #122309

Merged
merged 9 commits into from Mar 16, 2023

Conversation

QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Mar 9, 2023

This PR is to create a SearchBar widget which is the default trigger for a SearchView.
A SearchAnchor widget will be created soon to show search view.

Screenshot 2023-03-10 at 2 33 56 PM

Screenshot 2023-03-10 at 2 32 25 PM

In order to use the SearchBar with the new Material 3 colors, turn on the useMaterial3 flag in the ThemeData:

  return MaterialApp(
    theme: ThemeData(useMaterial3: true),
    // ...
  );

Related to #117483.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Mar 9, 2023
@QuncCccccc QuncCccccc changed the title [WIP]Create SearchBar and SearchTheme Create SearchBar and SearchTheme Mar 10, 2023
@QuncCccccc QuncCccccc changed the title Create SearchBar and SearchTheme Create SearchBar and SearchTheme Mar 10, 2023
@QuncCccccc QuncCccccc changed the title Create SearchBar and SearchTheme Create SearchBar and SearchBarTheme Mar 10, 2023
@QuncCccccc QuncCccccc force-pushed the create_search_bar branch 2 times, most recently from da283f3 to 4403dac Compare March 10, 2023 22:45
@QuncCccccc QuncCccccc marked this pull request as ready for review March 10, 2023 23:45
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

Nice work, just gave it a quick first pass.

dev/tools/gen_defaults/lib/search_bar_template.dart Outdated Show resolved Hide resolved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
Copy link
Member

Choose a reason for hiding this comment

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

Should this file be name search_bar.dart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I think the search bar will only be used for the widget SearchAnchor which will be created in the future PR, so just want to put them in the same file.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know what search anchor refers to, I couldn't find a mention in the guidelines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion. To open a search view, I'm creating a SearchAnchor widget so that we can get all the anchor(SearchBar or IconButton or any widget) information, such as size, position and etc. Here's the design doc https://docs.google.com/document/d/1_WOcgddfJ7OyYyaCJhkIWgOYywj2jDeMooFsKg012B4/edit#

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! I'm a bit confused because it talks about the introduction of 2 widgets, and the SearchView section only mentions SearchAnchor. Are these terms used interchangeably and should s/anchor/view/?

If SearchView and SearchAnchor are distinct widgets, is there a way to avoid having 3 public widgets? 2 would be ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. I think we will only need SearchBar and SearchAnchor widgets. Will update the design soon! Thanks:)

packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
Comment on lines 26 to 33
/// The [leading] widget is on the left side of the bar and should contain either
/// a navigational action (such as a menu or up-arrow) or a non-functional
/// search icon.
///
/// The [trailing] is an optional list. There should be up to two action icons
/// that are located on the bar’s right-hand side. These actions can represent
/// additional modes of searching (like voice search), a separate high-level
/// action (such as current location) or an overflow menu.
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in the constructor docs?

packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

Mostly just small stuff. This is looking good.

packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/search_anchor.dart Outdated Show resolved Hide resolved
this.padding,
this.textStyle,
this.hintStyle,
}) : assert(trailing == null || trailing.length <= 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to prevent developers from using 3 or more trailing widgets? Although it's definitely not advisable, it doesn't seem worth asserting if a developer founds a justification for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Removed this assertion.

surfaceTintColor: MaterialStatePropertyAll<Color>(Color(0xfffffff3)),
overlayColor: MaterialStatePropertyAll<Color>(Color(0xfffffff4)),
side: MaterialStatePropertyAll<BorderSide>(
BorderSide(width: 2.0, color: Color(0xfffffff5))),
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be on one line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this and others! I think the IDE did this kind of format automatically. Sorry for not catching this.

packages/flutter/test/material/search_bar_theme_test.dart Outdated Show resolved Hide resolved
packages/flutter/test/material/search_bar_theme_test.dart Outdated Show resolved Hide resolved
packages/flutter/test/material/search_bar_theme_test.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 120 to 129
/// The surface tint color of the button's [Material].
///
/// See [Material.surfaceTintColor] for more details.
///
/// If null, the value of [SearchBarThemeData.surfaceTintColor] will be used.
/// If this is also null, then the default value is [ColorScheme.surfaceTint].
final MaterialStateProperty<Color?>? surfaceTintColor;

/// The highlight color that's typically used to indicate that
/// the button is focused, hovered, or pressed.
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify what "the button" is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be "Search bar". Thanks for catching this. Fixed!

Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

LGTM pending documentation update for surfaceTintColor and overlayColor

@QuncCccccc QuncCccccc merged commit 5180e45 into flutter:master Mar 16, 2023
129 of 130 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants