I am having problems configuring Amplify API Subscriptions.
I modify the model User from one screen and I don’t receive any event from the subscription, even I print the message ‘Subscription established’
This is the code I execute at initialiazing the app and in the screens which I need to query the changes.
StreamSubscription<GraphQLResponse<User>>? subscription;
void subscribe() {
final subscriptionRequest = ModelSubscriptions.onCreate(User.classType);
final Stream<GraphQLResponse<User>> operation = Amplify.API.subscribe(
subscriptionRequest,
onEstablished: () => safePrint('Subscription established'),
);
subscription = operation.listen(
(event) {
safePrint('Subscription event data received: ${event.data}');
},
onError: (Object e) => safePrint('Error in subscription stream: $e'),
);
}
User model. In some tutorials, I watched no implementations were added to the model
type User @model @auth(rules: [{allow: public}]) {
username: String! @primaryKey
id: ID!
device_key: String
full_name: String
email: AWSEmail
tastes: AWSJSON
creator: Boolean
wallet: Float
wallet_creadores: AWSJSON
address: AWSJSON
}
I try to set up according Amplify Documentation recommends but I couldn’t make it work. I expected that initialiazing the subscription once, it would be enough to listen all the changes for that specific model.