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

add optional onSubmit callback #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions lib/src/anim_search_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,45 @@ class AnimSearchBar extends StatefulWidget {
final bool closeSearchOnSuffixTap;
final Color? color;
final List<TextInputFormatter>? inputFormatters;
final onSubmit;

const AnimSearchBar({
Key? key,
const AnimSearchBar(
{Key? key,

/// The width cannot be null
required this.width,
/// The width cannot be null
required this.width,

/// The textController cannot be null
required this.textController,
this.suffixIcon,
this.prefixIcon,
this.helpText = "Search...",
/// The textController cannot be null
required this.textController,
this.suffixIcon,
this.prefixIcon,
this.helpText = "Search...",

/// choose your custom color
this.color = Colors.white,
/// choose your custom color
this.color = Colors.white,

/// The onSuffixTap cannot be null
required this.onSuffixTap,
this.animationDurationInMilli = 375,
/// The onSuffixTap cannot be null
required this.onSuffixTap,
this.animationDurationInMilli = 375,

/// make the search bar to open from right to left
this.rtl = false,
/// make the search bar to open from right to left
this.rtl = false,

/// make the keyboard to show automatically when the searchbar is expanded
this.autoFocus = false,
/// make the keyboard to show automatically when the searchbar is expanded
this.autoFocus = false,

/// TextStyle of the contents inside the searchbar
this.style,
/// TextStyle of the contents inside the searchbar
this.style,

/// close the search on suffix tap
this.closeSearchOnSuffixTap = false,
/// close the search on suffix tap
this.closeSearchOnSuffixTap = false,

/// can add list of inputformatters to control the input
this.inputFormatters,
}) : super(key: key);
/// can add list of inputformatters to control the input
this.inputFormatters,

/// callback function when user submit text
this.onSubmit})
: super(key: key);

@override
_AnimSearchBarState createState() => _AnimSearchBarState();
Expand Down Expand Up @@ -208,6 +212,8 @@ class _AnimSearchBarState extends State<AnimSearchBar>
onEditingComplete: () {
/// on editing complete the keyboard will be closed and the search bar will be closed
unfocusKeyboard();

widget.onSubmit();
setState(() {
toggle = 0;
});
Expand Down