Last updated:
0 purchases
fkafka
Fkafka Dart Package #
The fkafka package offers an elegant solution for sending messages across different parts of your Dart or Flutter application without establishing direct connections. It simplifies event-driven programming by allowing you to emit and listen to topics anywhere in your app.
Features #
Emit Topics: Easily broadcast data across different parts of your app.
Listen to Topics: Set up listeners for specific topics and react to the data received.
Control Listeners: Ability to pause, resume, or close topic listeners.
Reconnect Capability: Automatically re-establish connections when they are closed.
Getting Started #
To get started with fkafka, add it to your project's dependencies:
For Flutter Projects #
flutter pub add fkafka
copied to clipboard
For Dart Projects #
dart pub add fkafka
copied to clipboard
Or manually add it to your pubspec.yaml file:
dependencies:
fkafka: ^2.0.0
copied to clipboard
Usage #
Import the package and create an instance of Fkafka:
import 'package:fkafka/fkafka.dart';
final kafka = Fkafka();
copied to clipboard
Emitting Data #
In this example, we're emitting a list of products:
// Assuming Product is a defined class
final List<Product> products = [
Product(name: 'phone', type: 'iphone', price: 1500.0),
];
// Emitting a list of products on the 'products.loaded' topic
kafka.emit('products.loaded', products);
copied to clipboard
Listening to Topics #
Set up a listener for the 'products.loaded' topic:
final kafka = Fkafka();
// Listening for the list of products
kafka.listen<List<Product>>(
'products.loaded',
onTopic: (List<Product> products) {
// Handle the received list of products
print(products);
},
);
copied to clipboard
Remember to close the instance when it's no longer needed:
kafka.closeInstance();
copied to clipboard
Managing Fkafka Instance #
To close all Fkafka instances and release resources:
Fkafka.closeAll();
copied to clipboard
Advanced Usage #
Pausing and Resuming Subscriptions: Control your topic listeners by pausing and resuming them as needed.
Check Active Listeners: Verify if a topic has active listeners in a particular instance.
Contributing #
Contributions to the fkafka package are welcome. Please read our contributing guidelines for more information.
License #
This project is licensed under the MIT License.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.