Skip to content

Add option to override search hint for full screen material search #18831

@hundeva

Description

@hundeva

The following example produces a very basic search screen. When the query is empty, it is displaying "Search" in the query field, which comes from hintText: MaterialLocalizations.of(context).searchFieldLabel (currently 425th line of search.dart).

Please add an option to override this hint text, and default back to it only when nothing else is provided. It could be either part of the passed delegate, or the way the search is opened, a new optional parameter could be provided, similar to the query parameter.

Example code:

class SearchApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Search demo'),
        ),
        body: Center(
          child: Builder(
            builder: (context) => MaterialButton(
                  child: Text('Search'),
                  onPressed: () => showSearch(
                        context: context,
                        delegate: DummyDelegate(),
                      ),
                ),
          ),
        ),
      ),
    );
  }
}

class DummyDelegate extends SearchDelegate<String> {
  @override
  List<Widget> buildActions(BuildContext context) => [];

  @override
  Widget buildLeading(BuildContext context) => IconButton(
        icon: Icon(Icons.close),
        onPressed: () => Navigator.of(context).pop(),
      );

  @override
  Widget buildResults(BuildContext context) => Text('Result');

  @override
  Widget buildSuggestions(BuildContext context) => Text('Suggestion');
}

Suggested solution 1:

                  onPressed: () => showSearch(
                        context: context,
                        delegate: DummyDelegate(),
                        hintText: 'My hint text',  // new way of overriding hint text
                      ),

Suggested solution 2:

class DummyDelegate extends SearchDelegate<String> {
  @override
  String get hintText => 'My hint text'; // new way of overriding hint text
  // rest of the delegate here
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions