AppBarWithSearchSwitch class
The AppBar that can switch into search field.
Use appBarBuilder property to build default AppBar with a search button which will call startSearch.
Use one of these callbacks to get text from TextField:
- onChanged,
- onSubmitted,
- or listen to textEditingController.
Also, there are callbacks for:
This widget support almost all properties of AppBar, but:
- leading and title properties are now expect -
Widget Function(context)?
:- this is made in order to access
AppBarWithSearchSwitch.of(context)
methods in them, - don't change them unless it necessary and use templates if you need to change them.
- this is made in order to access
- preferredSize here is a method, you should set it via toolbarWidth and toolbarHeight.
Here is a list of all other new properties(without mentioned above):
- this.tooltipForClearButton = 'Clear',
- this.tooltipForCloseButton = 'Close search',
- this.closeSearchIcon = Icons.close,
- this.clearSearchIcon = Icons.backspace,
- this.fieldHintText = 'Search',
- this.keepAppBarColors = true,
- this.closeOnSubmit = true,
- this.clearOnSubmit = false,
- this.clearOnClose = false,
- this.showClearButton = true,
- this.closeOnClearTwice = true,
- this.keyboardType = TextInputType.text,
- this.toolbarWidth = double.infinity,
- this.searchInputDecoration,
- // And controller
- this.customTextEditingController, // has default static value
- // And notifiers:
- this.customIsSearchModeNotifier, // has default static value
- this.customHasText, // has default static value
- this.customTextNotifier, // has default static value
- this.customSubmitNotifier, // has default static value
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- ProxyWidget
- InheritedWidget
- AppBarWithSearchSwitch
- Implemented types
Constructors
-
AppBarWithSearchSwitch({required PreferredSizeWidget appBarBuilder(BuildContext context), Key? key, void onChanged(String value)?, VoidCallback? onClosed, void onSubmitted(String value)?, VoidCallback? onCleared, String tooltipForClearButton = 'Clear', String tooltipForCloseButton = 'Close search', IconData? closeSearchIcon = Icons.close, IconData? clearSearchIcon = Icons.backspace, String fieldHintText = 'Search', bool keepAppBarColors = true, bool closeOnSubmit = true, bool clearOnSubmit = false, bool clearOnClose = false, bool showClearButton = true, bool closeOnClearTwice = true, bool submitOnClearTwice = true, TextInputType keyboardType = TextInputType.text, double toolbarWidth = double.infinity, InputDecoration? searchInputDecoration, Widget animation(Widget child)?, ValueNotifier<
bool> ? customIsSearchModeNotifier, ValueNotifier<bool> ? customIsActiveNotifier, ValueNotifier<String> ? customTextNotifier, ValueNotifier<String> ? customSubmitNotifier, ValueNotifier<bool> ? customHasText, TextEditingController? customTextEditingController, Widget leading(BuildContext context)?, Widget title(BuildContext context)?, List<Widget> ? actions, bool automaticallyImplyLeading = true, Widget? flexibleSpace, PreferredSizeWidget? bottom, double? elevation, double? scrolledUnderElevation, Color? shadowColor, Color? surfaceTintColor, ShapeBorder? shape, Color? backgroundColor, Color? foregroundColor, IconThemeData? iconTheme, IconThemeData? actionsIconTheme, bool primary = true, bool? centerTitle, bool excludeHeaderSemantics = false, double? titleSpacing, double toolbarOpacity = 1.0, double bottomOpacity = 1.0, double? toolbarHeight, double? leadingWidth, TextStyle? toolbarTextStyle, TextStyle? titleTextStyle, SystemUiOverlayStyle? systemOverlayStyle, ThemeData? theme})
Properties
-
actions
→ List<
Widget> ? -
See AppBar documentation for help.
final
- actionsIconTheme → IconThemeData?
-
See AppBar documentation for help.
final
- animation → (Widget Function(Widget child)?)
-
A function that return an Animation Widget to animate transition to and from SearchMode of AppBarWithSearchSwitch.
final
- appBarBuilder → PreferredSizeWidget Function(BuildContext context)
-
Builder function for AppBar by default (when search is inactive).
final
- automaticallyImplyLeading → bool
-
See AppBar documentation for help.
final
- backgroundColor → Color?
-
See AppBar documentation for help.
final
- bottom → PreferredSizeWidget?
-
See AppBar documentation for help.
final
- bottomOpacity → double
-
See AppBar documentation for help.
final
- centerTitle → bool?
-
See AppBar documentation for help.
final
- child → Widget
-
The widget below this widget in the tree.
finalinherited
- clearOnClose → bool
-
Clear TextEditController on close.
final
- clearOnSubmit → bool
-
Whether the text field should be cleared when it is submitted
final
- clearSearchIcon → IconData?
-
Icon for button clear search.
final
- closeOnClearTwice → bool
-
The click on clear button will hide search field, if text field is already empty. Defaults to true.
final
- closeOnSubmit → bool
-
Whether or not the search bar should close on submit. Defaults to true.
final
- closeSearchIcon → IconData?
-
Icon for button close search.
final
-
customHasText
→ ValueNotifier<
bool> ? -
Read only ValueNotifier for the TextField in search app bar.
final
-
customIsActiveNotifier
→ ValueNotifier<
bool> ? -
Shortcut for customIsSearchModeNotifier, for backward compatibility.
final
-
customIsSearchModeNotifier
→ ValueNotifier<
bool> ? -
The ValueNotifier to be used to indicate: is text field visible.
final
-
customSubmitNotifier
→ ValueNotifier<
String> ? -
The ValueNotifier submitNotifier for the TextField in search app bar.
final
- customTextEditingController → TextEditingController?
-
The TextEditingController for the TextField in search app bar.
final
-
customTextNotifier
→ ValueNotifier<
String> ? -
The ValueNotifier textNotifier for the TextField in search app bar.
final
- elevation → double?
-
See AppBar documentation for help.
final
- excludeHeaderSemantics → bool
-
See AppBar documentation for help.
final
- fieldHintText → String
-
What the hintText on the search bar should be. Defaults to 'Search'.
final
- flexibleSpace → Widget?
-
See AppBar documentation for help.
final
- foregroundColor → Color?
-
See AppBar documentation for help.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
hasText
→ ValueNotifier<
bool> -
The ValueNotifier hasText for the TextField in search app bar.
no setter
- iconTheme → IconThemeData?
-
See AppBar documentation for help.
final
-
isActive
→ ValueNotifier<
bool> -
Shortcut for isSearchMode, for backward compatibility.
no setter
-
isSearchMode
→ ValueNotifier<
bool> -
Indicator of whenever search bar is active.
no setter
- keepAppBarColors → bool
-
It was used for old Material Theme 2:
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- keyboardType → TextInputType
-
The type of keyboard to use for editing the search bar text. Defaults to 'TextInputType.text'.
final
- leading → (Widget Function(BuildContext context)?)
-
Builder function for leading button of search app bar. Defaults to null.
final
- leadingWidth → double?
-
See AppBar documentation for help.
final
- onChanged → (void Function(String value)?)
-
A callback which is invoked each time the text field's value changes.
final
- onCleared → VoidCallback?
-
A callback which is fired when clear button is pressed.
final
- onClosed → VoidCallback?
-
A callback which gets fired on close button press.
final
- onSubmitted → (void Function(String value)?)
-
A callback fired every time the text is submitted.
final
- preferredSize → Size
-
Standard overridden method of PreferredSizeWidget.
no setteroverride
- primary → bool
-
See AppBar documentation for help.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrolledUnderElevation → double?
-
See AppBar documentation for help.
final
- searchFocusNode ↔ FocusNode?
-
Get FocusNode that will be activated when isSearchMode == true
getter/setter pair
- searchInputDecoration → InputDecoration?
-
Custom InputDecoration for Search TextField.
final
- shadowColor → Color?
-
See AppBar documentation for help.
final
- shape → ShapeBorder?
-
See AppBar documentation for help.
final
- showClearButton → bool
-
Whether or not the search bar should add a clear input button, defaults to true.
final
-
submitNotifier
→ ValueNotifier<
String> -
The ValueNotifier submitNotifier for the TextField in search app bar.
no setter
- submitOnClearTwice → bool
-
If closeOnClearTwice=true close button will also trigger onSubmitted. Defaults to true.
final
- surfaceTintColor → Color?
-
See AppBar documentation for help.
final
- systemOverlayStyle → SystemUiOverlayStyle?
-
See AppBar documentation for help.
final
- text → String
-
Text in the field.
no setter
- textEditingController → TextEditingController
-
The TextEditingController for the TextField in search app bar.
no setter
-
textNotifier
→ ValueNotifier<
String> -
The ValueNotifier for the TextField in search app bar.
no setter
- theme → ThemeData?
-
Theme for AppBar, when isSearchMode == true.
final
- title → (Widget Function(BuildContext context)?)
-
Builder function for title of search app bar, expected TextField. Defaults to null.
final
- titleSpacing → double?
-
See AppBar documentation for help.
final
- titleTextStyle → TextStyle?
-
See AppBar documentation for help.
final
- toolbarHeight → double?
-
See AppBar documentation for help.
final
- toolbarOpacity → double
-
See AppBar documentation for help.
final
- toolbarTextStyle → TextStyle?
-
See AppBar documentation for help.
final
- toolbarWidth → double
-
Width of AppBar, defaults to double.infinity.
final
- tooltipForClearButton → String
-
The tooltip for ClearButton of search text field. Defaults to 'Clear'.
final
- tooltipForCloseButton → String
-
Tooltip for button close search.
final
Methods
-
clearText(
) → void - Clear text in search field.
-
createElement(
) → InheritedElement -
Inflates this configuration to a concrete instance.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startSearch(
) → void - Show the search bar.
-
stopSearch(
) → void - Hide the search bar.
-
submitCallbackForTextField(
dynamic val) → void - In case you implement you own title builder, use this as callback for TextField.onSubmitted.
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
-
triggerSearch(
) → void - Show/hide the search bar.
-
updateShouldNotify(
covariant AppBarWithSearchSwitch oldWidget) → bool -
Currently rebuild is triggered only if isSearchMode changed.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of(
BuildContext context) → AppBarWithSearchSwitch? - Standard getter of the class.