From 33f19ebd5d89a458aa29b3c137f880b86c06d3ab Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 10 Jun 2021 11:06:15 +0200 Subject: [PATCH] add comments --- .../lib/src/better_stream_builder.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/stream_chat_flutter_core/lib/src/better_stream_builder.dart b/packages/stream_chat_flutter_core/lib/src/better_stream_builder.dart index 9691618a..a51c0762 100644 --- a/packages/stream_chat_flutter_core/lib/src/better_stream_builder.dart +++ b/packages/stream_chat_flutter_core/lib/src/better_stream_builder.dart @@ -2,7 +2,12 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; +/// A more efficient [StreamBuilder] +/// It requires [initialData] and will rebuild +/// only when the new data is different than the current data +/// The [comparator] is used to check if the new data is different class BetterStreamBuilder extends StatefulWidget { + /// Creates a new BetterStreamBuilder const BetterStreamBuilder({ required this.stream, required this.initialData, @@ -13,11 +18,22 @@ class BetterStreamBuilder extends StatefulWidget { Key? key, }) : super(key: key); + /// The stream to listen to final Stream? stream; + + /// The initial data available final T initialData; + + /// Comparator used to check if the new data is different than the last one final bool Function(T?, T)? comparator; + + /// Builder that builds based on the new snapshot final Widget Function(BuildContext context, T data) builder; + + /// Builder that builds when the data is null final Widget Function(BuildContext context)? loadingBuilder; + + /// Builder used when there is an error final Widget Function(BuildContext context, Object error)? errorBuilder; @override