Skip to content

Commit

Permalink
add rrousselGit#854 Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 28, 2024
1 parent 229124a commit 527c58a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/provider/lib/src/consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ class Consumer<T> extends SingleChildStatelessWidget {
Key? key,
required this.builder,
Widget? child,
this.listener,
}) : super(key: key, child: child);

// {@codexsourav}
void Function(BuildContext context, T)? listener;

/// {@template provider.consumer.builder}
/// Build a widget tree based on the value from a [Provider<T>].
///
Expand All @@ -176,6 +180,9 @@ class Consumer<T> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(context, Provider.of<T>(context));
}
return builder(
context,
Provider.of<T>(context),
Expand All @@ -191,7 +198,10 @@ class Consumer2<A, B> extends SingleChildStatelessWidget {
Key? key,
required this.builder,
Widget? child,
this.listener,
}) : super(key: key, child: child);
// {@codexsourav}
void Function(BuildContext context, A, B)? listener;

/// {@macro provider.consumer.builder}
final Widget Function(
Expand All @@ -203,6 +213,9 @@ class Consumer2<A, B> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(context, Provider.of<A>(context), Provider.of<B>(context));
}
return builder(
context,
Provider.of<A>(context),
Expand All @@ -219,7 +232,10 @@ class Consumer3<A, B, C> extends SingleChildStatelessWidget {
Key? key,
required this.builder,
Widget? child,
this.listener,
}) : super(key: key, child: child);
// {@codexsourav}
void Function(BuildContext context, A, B, C)? listener;

/// {@macro provider.consumer.builder}
final Widget Function(
Expand All @@ -232,6 +248,14 @@ class Consumer3<A, B, C> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(
context,
Provider.of<A>(context),
Provider.of<B>(context),
Provider.of<C>(context),
);
}
return builder(
context,
Provider.of<A>(context),
Expand All @@ -249,8 +273,12 @@ class Consumer4<A, B, C, D> extends SingleChildStatelessWidget {
Key? key,
required this.builder,
Widget? child,
this.listener,
}) : super(key: key, child: child);

// {@codexsourav}
void Function(BuildContext context, A, B, C, D)? listener;

/// {@macro provider.consumer.builder}
final Widget Function(
BuildContext context,
Expand All @@ -263,6 +291,15 @@ class Consumer4<A, B, C, D> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(
context,
Provider.of<A>(context),
Provider.of<B>(context),
Provider.of<C>(context),
Provider.of<D>(context),
);
}
return builder(
context,
Provider.of<A>(context),
Expand All @@ -283,6 +320,9 @@ class Consumer5<A, B, C, D, E> extends SingleChildStatelessWidget {
Widget? child,
}) : super(key: key, child: child);

// {@codexsourav}
void Function(BuildContext context, A, B, C, D, E)? listener;

/// {@macro provider.consumer.builder}
final Widget Function(
BuildContext context,
Expand All @@ -296,6 +336,17 @@ class Consumer5<A, B, C, D, E> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(
context,
Provider.of<A>(context),
Provider.of<B>(context),
Provider.of<C>(context),
Provider.of<D>(context),
Provider.of<E>(context),
);
}

return builder(
context,
Provider.of<A>(context),
Expand All @@ -317,6 +368,9 @@ class Consumer6<A, B, C, D, E, F> extends SingleChildStatelessWidget {
Widget? child,
}) : super(key: key, child: child);

// {@codexsourav}
void Function(BuildContext context, A, B, C, D, E, F)? listener;

/// {@macro provider.consumer.builder}
final Widget Function(
BuildContext context,
Expand All @@ -331,6 +385,17 @@ class Consumer6<A, B, C, D, E, F> extends SingleChildStatelessWidget {

@override
Widget buildWithChild(BuildContext context, Widget? child) {
if (listener != null) {
listener!(
context,
Provider.of<A>(context),
Provider.of<B>(context),
Provider.of<C>(context),
Provider.of<D>(context),
Provider.of<E>(context),
Provider.of<F>(context),
);
}
return builder(
context,
Provider.of<A>(context),
Expand Down

0 comments on commit 527c58a

Please sign in to comment.