From 527c58a79f6f1b0c0ddd5dbfee2d7e8a3dc403b3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 29 Jan 2024 02:48:22 +0530 Subject: [PATCH] add #854 Listener --- packages/provider/lib/src/consumer.dart | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/packages/provider/lib/src/consumer.dart b/packages/provider/lib/src/consumer.dart index 331c9402..6a2c4684 100644 --- a/packages/provider/lib/src/consumer.dart +++ b/packages/provider/lib/src/consumer.dart @@ -161,8 +161,12 @@ class Consumer 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]. /// @@ -176,6 +180,9 @@ class Consumer extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!(context, Provider.of(context)); + } return builder( context, Provider.of(context), @@ -191,7 +198,10 @@ class Consumer2 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( @@ -203,6 +213,9 @@ class Consumer2 extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!(context, Provider.of(context), Provider.of(context)); + } return builder( context, Provider.of(context), @@ -219,7 +232,10 @@ class Consumer3 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( @@ -232,6 +248,14 @@ class Consumer3 extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!( + context, + Provider.of(context), + Provider.of(context), + Provider.of(context), + ); + } return builder( context, Provider.of(context), @@ -249,8 +273,12 @@ class Consumer4 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, @@ -263,6 +291,15 @@ class Consumer4 extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!( + context, + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + ); + } return builder( context, Provider.of(context), @@ -283,6 +320,9 @@ class Consumer5 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, @@ -296,6 +336,17 @@ class Consumer5 extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!( + context, + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + ); + } + return builder( context, Provider.of(context), @@ -317,6 +368,9 @@ class Consumer6 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, @@ -331,6 +385,17 @@ class Consumer6 extends SingleChildStatelessWidget { @override Widget buildWithChild(BuildContext context, Widget? child) { + if (listener != null) { + listener!( + context, + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + Provider.of(context), + ); + } return builder( context, Provider.of(context),