-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
FlutterFeathersJS instance is the singleton. I have repository wrapper and listen method:
abstract class FeathersLocalRepo<Entity> {
late Logger log;
abstract String serviceName;
Entity fromMap(Map<String, dynamic> map);
final FlutterFeathersjs _client;
FeathersLocalRepo({required FlutterFeathersjs client}) : _client = client {
log = Logger('${serviceName}Repo');
}
...
Future<StreamSubscription<FeathersJsEventData>> listen(
void Function(FeathersJsEventData<dynamic>) listener,
) async {
await _client.waitClientBeReady();
final id = Random().nextInt(999);
log.info("Setup listener $id");
return _client
.socketListen(serviceName: serviceName, fromJson: fromMap)
.listen((event) {
log.info("Event received: $event on $id");
listener(event);
});
}and output:
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:02.014553: Listener setup
I/flutter ( 4535): INFO: customer-chat-messagesRepo : 2025-09-25 15:16:02.024819: Setup listener 177
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:05.904523: Listener closed // <- close page and open again
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:06.442680: Listener setup
I/flutter ( 4535): INFO: customer-chat-messagesRepo : 2025-09-25 15:16:06.446800: Setup listener 332
I/flutter ( 4535): INFO: customer-chat-messagesRepo : 2025-09-25 15:16:12.262793: Event received: Instance of 'FeathersJsEventData<dynamic>' on 332
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:12.263101: event received by subscription 738179784
I/flutter ( 4535): INFO: customer-chat-messagesRepo : 2025-09-25 15:16:12.263482: Event received: Instance of 'FeathersJsEventData<dynamic>' on 332
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:12.263550: event received by subscription 738179784
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:12.264223: Received chat message: Instance of 'NoteMessageContent'
I/flutter ( 4535): INFO: CustomerChat : 2025-09-25 15:16:12.264635: Received chat message: Instance of 'NoteMessageContent'
To Reproduce
Steps to reproduce the behavior:
- Make FlutterFeathersJS a singleton
- On a state/widget make listen on service
- Open this page twice/3 times (doesn't matter navigator or self). Don't forget to close on dispose.
- Send event after reopening. Stream will receive duplicated events
Expected behavior
Only one event
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Android
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 4.0.4]
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working