Skip to content

Instantly share code, notes, and snippets.

@Ingco
Last active May 7, 2021 14:44
Show Gist options
  • Save Ingco/21ee2f8958977306b83f1df4e6cde070 to your computer and use it in GitHub Desktop.
Save Ingco/21ee2f8958977306b83f1df4e6cde070 to your computer and use it in GitHub Desktop.
class RecommendationStream {
RecommendationStream() {
...
_notificator.outEvent.listen((event) {
print('ЭТОТ ТЕКСТ ПЕЧАТАЕТ ДВАЖДЫ');
if (event == ProfileScreenEvents.UPDATE_LOCAL) {
send();
} else if (event == ProfileScreenEvents.UPDATE_REMOTE) {
sendNew();
}
});
}
...
}
...
onTap: () {
Navigator.pushNamed(
context,
SettingsScreen.routeName,
arguments: args,
).then((value) {
context
.read<MainSourceData>()
.notificator
.inEvent
.add(ProfileScreenEvents.UPDATE_REMOTE);
});
},
...
...
Navigator.pushNamedAndRemoveUntil(
context,
UserProfileScreen.routeName,
ModalRoute.withName(StartScreen.routeName),
arguments: args,
);
Timer(
Duration(seconds: 3),
() {
ProfileScreenNotification _notificator = ProfileScreenNotification();
StreamSink<ProfileScreenEvents> profileUpdater = _notificator.inEvent;
profileUpdater.add(ProfileScreenEvents.UPDATE_REMOTE);
}
);
...
import 'dart:async';
enum ProfileScreenEvents { UPDATE_LOCAL, UPDATE_REMOTE }
class ProfileScreenNotification {
static final ProfileScreenNotification _instance = ProfileScreenNotification._();
ProfileScreenNotification._();
factory ProfileScreenNotification() {
return _instance;
}
StreamController<ProfileScreenEvents> _controller =
StreamController<ProfileScreenEvents>.broadcast();
StreamSink<ProfileScreenEvents> get inEvent => _controller.sink;
Stream<ProfileScreenEvents> get outEvent => _controller.stream;
void dispose() {
_controller.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment