Commit 7024a6a9 by Rizal Hermawan

refactor : clears hint text after click close on appbar

parent d388ed49
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs, must_be_immutable, doc_directive_has_extra_arguments
part of 'floating_search_bar.dart'; part of 'floating_search_bar.dart';
...@@ -12,7 +12,7 @@ typedef OnFocusChangedCallback = void Function(bool isFocused); ...@@ -12,7 +12,7 @@ typedef OnFocusChangedCallback = void Function(bool isFocused);
/// This can be considered the base Widget for the full /// This can be considered the base Widget for the full
/// [FloatingSearchBar]. /// [FloatingSearchBar].
class FloatingSearchAppBar extends ImplicitlyAnimatedWidget { class FloatingSearchAppBar extends ImplicitlyAnimatedWidget {
const FloatingSearchAppBar({ FloatingSearchAppBar({
Key? key, Key? key,
Duration implicitDuration = const Duration(milliseconds: 500), Duration implicitDuration = const Duration(milliseconds: 500),
Curve implicitCurve = Curves.linear, Curve implicitCurve = Curves.linear,
...@@ -154,7 +154,7 @@ class FloatingSearchAppBar extends ImplicitlyAnimatedWidget { ...@@ -154,7 +154,7 @@ class FloatingSearchAppBar extends ImplicitlyAnimatedWidget {
final Widget? title; final Widget? title;
/// {@macro floating_search_bar.hint} /// {@macro floating_search_bar.hint}
final String? hint; String? hint;
/// {@macro floating_search_bar.actions} /// {@macro floating_search_bar.actions}
final List<Widget>? actions; final List<Widget>? actions;
...@@ -212,12 +212,8 @@ class FloatingSearchAppBarState extends ImplicitlyAnimatedWidgetState< ...@@ -212,12 +212,8 @@ class FloatingSearchAppBarState extends ImplicitlyAnimatedWidgetState<
if (status == AnimationStatus.dismissed) { if (status == AnimationStatus.dismissed) {
if (widget.clearQueryOnClose) { if (widget.clearQueryOnClose) {
if (widget.autoRemoveControllerValue == null) { if (widget.autoRemoveControllerValue == null || widget.autoRemoveControllerValue! == true) {
clear(); clear();
} else {
if (widget.autoRemoveControllerValue! == true) {
clear();
}
} }
} }
} }
...@@ -382,7 +378,15 @@ class FloatingSearchAppBarState extends ImplicitlyAnimatedWidgetState< ...@@ -382,7 +378,15 @@ class FloatingSearchAppBarState extends ImplicitlyAnimatedWidgetState<
_input.clearFocus(); _input.clearFocus();
} }
void clear() => _input.clear(); void clear() {
final bool hasQuery = !widget.clearQueryOnClose && query.isNotEmpty;
if (hasQuery == true) {
setState(() {
widget.hint = '';
});
}
_input.clear();
}
void _assignController() => widget.controller?._appBarState = this; void _assignController() => widget.controller?._appBarState = this;
......
// ignore_for_file: doc_directive_has_extra_arguments
import 'dart:math'; import 'dart:math';
import 'dart:ui'; import 'dart:ui';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment