search_bar_bloc 1.0.1 search_bar_bloc: ^1.0.1 copied to clipboard
A Flutter package for creating a SearchBar that uses bloc package to handle the state.
Bloc Provider Example #
Here is a quick example of how to implement the search bar with a BlocProvider.
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => SearchBarCubit(),
child: Column(
children: [
const SearchBar(hintText: "Search something..."),
BlocBuilder<SearchBarCubit, SearchBarState>(
buildWhen: (previous, current) => previous.content != current.content,
builder: (context, state) {
return Text("You are searching : ${state.content}");
}),
],
),
);
}
Bloc Provider Example #
Here is a quick example of how to implement the search bar with a BlocListener.
class BlockBuilderExampleWidget extends StatelessWidget {
const BlockBuilderExampleWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocListener<SearchBarCubit, SearchBarState>(
listenWhen: (previous, current) => previous.content != current.content,
listener: (context, state) {
print("You are searching : ${state.content}");
},
child: Container(),
);
}
}