ispectify_bloc 4.1.3-dev12
ispectify_bloc: ^4.1.3-dev12 copied to clipboard
An additional package for BLoC (logging and handling).
π Overview #
ISpectify BLoC provides seamless integration between BLoC state management and the ISpectify logging system.
π State Tracking β’ π Event Logging β’ π Transition Monitoring β’ β Error Handling
Enhance your BLoC debugging workflow by automatically capturing and logging all state management interactions. Perfect for tracking state changes, debugging complex flows, and monitoring application behavior.
π― Key Features #
- π State Change Logging: Automatic logging of all BLoC state changes
- π Event Tracking: Detailed event logging with parameters
- π Transition Monitoring: Complete state transition tracking
- β Error Handling: BLoC error logging with stack traces
- β‘ Performance Metrics: State change timing and performance tracking
- ποΈ Configurable: Flexible filtering and formatting options
π§ Configuration Options #
Basic Configuration #
Bloc.observer = ISpectifyBlocObserver(
ispectify: ispectify,
settings: ISpectifyBlocSettings(
// Event logging
printEvents: true,
// State logging
printStates: true,
// Transition logging
printTransitions: true,
// Change logging
printChanges: true,
// Error handling
printErrors: true,
),
);
Advanced Filtering #
Bloc.observer = ISpectifyBlocObserver(
ispectify: ispectify,
settings: ISpectifyBlocSettings(
// Filter specific BLoCs
blocFilter: (bloc) => bloc.runtimeType != NavigationBloc,
// Filter sensitive events
eventFilter: (event) {
if (event is AuthEvent) {
return event.copyWith(password: '***');
}
return event;
},
// Filter states
stateFilter: (state) {
if (state is UserState) {
return state.copyWith(sensitiveData: null);
}
return state;
},
// Custom log levels
eventLogLevel: LogLevel.debug,
stateLogLevel: LogLevel.info,
errorLogLevel: LogLevel.error,
),
);
π¦ Installation #
Add ispectify_bloc to your pubspec.yaml:
dependencies:
ispectify_bloc: ^4.1.3
π Quick Start #
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ispectify_bloc/ispectify_bloc.dart';
import 'package:ispectify/ispectify.dart';
void main() {
final ispectify = ISpectify();
// Set up BLoC observer
Bloc.observer = ISpectifyBlocObserver(
ispectify: ispectify,
settings: ISpectifyBlocSettings(
printEvents: true,
printStates: true,
printTransitions: true,
printChanges: true,
),
);
runApp(MyApp());
}
// Your BLoC will be automatically logged
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncremented>((event, emit) {
emit(state + 1);
});
}
}
βοΈ Advanced Features #
Custom Log Formatting #
Bloc.observer = ISpectifyBlocObserver(
ispectify: ispectify,
settings: ISpectifyBlocSettings(
eventFormatter: (bloc, event) => '${bloc.runtimeType}: ${event.runtimeType}',
stateFormatter: (bloc, state) => '${bloc.runtimeType} -> ${state.runtimeType}',
transitionFormatter: (bloc, transition) =>
'${bloc.runtimeType}: ${transition.event.runtimeType} -> ${transition.nextState.runtimeType}',
),
);
Performance Monitoring #
Bloc.observer = ISpectifyBlocObserver(
ispectify: ispectify,
settings: ISpectifyBlocSettings(
trackPerformance: true,
performanceThreshold: Duration(milliseconds: 100), // Log slow transitions
),
);
Multiple Observers #
// Combine with other observers
class MultiBlocObserver extends BlocObserver {
final List<BlocObserver> _observers;
MultiBlocObserver(this._observers);
@override
void onChange(BlocBase bloc, Change change) {
for (final observer in _observers) {
observer.onChange(bloc, change);
}
}
// Implement other methods...
}
Bloc.observer = MultiBlocObserver([
ISpectifyBlocObserver(ispectify: ispectify),
CustomBlocObserver(),
]);
π Examples #
See the example/ directory for complete integration examples with different BLoC patterns.
ποΈ Architecture #
ISpectifyBloc integrates with the BLoC library through observers:
| Component | Description |
|---|---|
| BLoC Observer | Captures all BLoC events and state changes |
| Event Logger | Logs events with parameters and metadata |
| State Logger | Logs state changes and transitions |
| Error Handler | Captures and logs BLoC errors |
| Performance Tracker | Measures state change performance |
π€ Contributing #
Contributions are welcome! Please read our contributing guidelines and submit pull requests to the main branch.
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π Related Packages #
- ispectify - Foundation logging system
- ispect - Main debugging interface
- flutter_bloc - BLoC state management library
- bloc - Core BLoC library