simple_refresh_bus 1.0.0 copy "simple_refresh_bus: ^1.0.0" to clipboard
simple_refresh_bus: ^1.0.0 copied to clipboard

A lightweight event bus for cross-cubit state synchronization in Flutter BLoC apps. Zero config, type-safe refresh signals and data passing.

Simple Refresh Bus #

A lightweight event bus for cross-cubit/bloc state synchronization in Flutter BLoC applications.

Installation #

dependencies:
  simple_refresh_bus: ^1.0.0

Usage #

Subscribe to refresh signals (Cubit) #

class ProfileGetCubit extends Cubit<ProfileGetState>
    with RefreshBusSubscriber<ProfileGetState> {

  ProfileGetCubit() : super(const ProfileGetState()) {
    onRefresh<Profile>(load);  // Reload when Profile signal received
  }

  Future<void> load() async {
    // Fetch from API...
  }
}

Subscribe to refresh signals (Bloc) #

class ProfileBloc extends Bloc<ProfileEvent, ProfileState>
    with RefreshBusSubscriber<ProfileState> {

  ProfileBloc() : super(const ProfileState()) {
    on<ProfileLoadRequested>(_onLoadRequested);
    onRefresh<Profile>(() async => add(ProfileLoadRequested()));
  }
}

Emit refresh signals #

// Trigger reload on all listeners
RefreshBus.instance.refresh<Profile>();

// Or pass data directly (listeners receive it via onData)
RefreshBus.instance.push<Profile>(updatedProfile);

Listen for data #

onData<Profile>((profile) => emit(state.copyWith(profile: profile)));

Testing #

Override refreshBus to use an isolated instance:

class TestableProfileCubit extends ProfileGetCubit {
  final RefreshBus _testBus;
  TestableProfileCubit(this._testBus);

  @override
  RefreshBus get refreshBus => _testBus;
}

// In tests
final testBus = RefreshBus.custom();
final cubit = TestableProfileCubit(testBus);
testBus.refresh<Profile>();  // Triggers cubit reload

License #

MIT

1
likes
150
points
115
downloads

Publisher

verified publisherkeep-it-simple.dev

Weekly Downloads

A lightweight event bus for cross-cubit state synchronization in Flutter BLoC apps. Zero config, type-safe refresh signals and data passing.

Repository (GitHub)
View/report issues

Topics

#bloc #cubit #state-management #event-bus #flutter

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_bloc

More

Packages that depend on simple_refresh_bus