streamBuilder<T> method

StreamBuilder<T> streamBuilder<T>(
  1. T map(
    1. S
    ), {
  2. Key? key,
  3. T? initialState,
  4. bool log = false,
  5. required AsyncWidgetBuilder<T> builder,
})

Implementation

StreamBuilder<T> streamBuilder<T>(
  T Function(S) map, {
  Key? key,
  T? initialState,
  bool log = false,
  required AsyncWidgetBuilder<T> builder,
}) {
  final initialData = initialState ?? map(currentState);
  return StreamBuilder<T>(
    key: key,
    initialData: initialData,
    stream: state.map(map).distinct((one, two) {
      if (log) {
        Fimber.d("------ streamBuilder.equals $one $two ${one == two}");
      }
      return one == two;
    }),
    builder: (
      BuildContext context,
      AsyncSnapshot<T> snapshot,
    ) {
      if (log) {
        Fimber.d("------ streamBuilder ${snapshot.data ?? initialData}");
      }
      return builder(context, snapshot);
    },
  );
}