felangel / bloc

A predictable state management library that helps implement the BLoC design pattern

Home Page:https://bloclibrary.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: listen method in BuildContext extension as functioning BlocListener

Jaew00Shin opened this issue · comments

Description

I usually use context.watch, context.select, context.read instead of BlocBuilder, BlocSelector. Because, it makes widget tree more clear to use extension method in BuildContext than class widgets.

But there is no context.listen. So I should use BlocListener.
I want to use context.listen method instead of BlocListener.

Desired Solution

context.listen<AppBloc, AppState>((context, state) {}, listenWhen: (prev, curr) => true);

The first positional parameter is a function which has two parameters, BuildContext and the state of Bloc respectively.
listenWhen is the named parameter and it functions like listenWhen in BlocListener class.

That's context.select in a long form.
Can you give more explanation about your use-case?