talker_bloc_logger 4.1.3 copy "talker_bloc_logger: ^4.1.3" to clipboard
talker_bloc_logger: ^4.1.3 copied to clipboard

Lightweight and customizable BLoC state management library logger on talker base.

example/talker_bloc_logger_example.dart

import 'package:bloc/bloc.dart';
import 'package:talker_bloc_logger/talker_bloc_logger.dart';

void main() async {
  Bloc.observer = TalkerBlocObserver(
    settings: TalkerBlocLoggerSettings(
      enabled: true,
      printEventFullData: false,
      printStateFullData: false,
      printChanges: true,
      printClosings: true,
      printCreations: true,
      printEvents: true,
      printTransitions: true,
      // If you want log only AuthBloc transitions
      transitionFilter: (bloc, transition) =>
          bloc.runtimeType.toString() == 'AuthBloc',
      // If you want log only AuthBloc events
      eventFilter: (bloc, event) => bloc.runtimeType.toString() == 'AuthBloc',
    ),
  );
  final somethingBloc = SomethingBloc();
  somethingBloc.add(LoadSomething(LoadSomethingCase.successful));
  await Future.delayed(const Duration(milliseconds: 300));
  somethingBloc.add(LoadSomething(LoadSomethingCase.failure));
}

enum LoadSomethingCase { successful, failure }

class SomethingBloc extends Bloc<SomethingEvent, SomethingState> {
  SomethingBloc() : super(SomethingInitial()) {
    on<LoadSomething>((event, emit) {
      emit(SomethingLoading());
      if (event.loadCase == LoadSomethingCase.successful) {
        emit(SomethingLoaded());
        return;
      }
      throw Exception('Load something failure');
    });
  }
}

abstract class SomethingEvent {}

class LoadSomething extends SomethingEvent {
  LoadSomething(this.loadCase);

  final LoadSomethingCase loadCase;
}

abstract class SomethingState {}

class SomethingInitial extends SomethingState {}

class SomethingLoading extends SomethingState {}

class SomethingLoaded extends SomethingState {}

class SomethingLoadingFailure extends SomethingState {
  SomethingLoadingFailure(this.exception);
  final Object? exception;
}
31
likes
0
pub points
96%
popularity

Publisher

verified publisherfrezycode.com

Lightweight and customizable BLoC state management library logger on talker base.

Repository (GitHub)
View/report issues

Topics

#bloc #state #cubit #logging

License

unknown (license)

Dependencies

bloc, meta, talker

More

Packages that depend on talker_bloc_logger