stateBuilder<T> method

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

Implementation

StreamBuilder<T> stateBuilder<T>(
  T Function(S) map, {
  Key? key,
  T? initialState,
  bool log = false,
  required AsyncWidgetBuilderKokoro<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("------ stateBuilder.equals $one $two ${one == two}");
      }
      return one == two;
    }),
    builder: (
      BuildContext context,
      AsyncSnapshot<T> snapshot,
    ) {
      if (log) {
        Fimber.d("------ stateBuilder ${snapshot.data ?? initialData}");
      }
      return builder(context, snapshot.data ?? initialData);
    },
  );
}