I am building a messaging system in my flutter app using the get stream api. Right now, I want to delete a channel in case two users stop being friends or a user deletes their account. The documentation is not very clear on how to delete a single channel in flutter.
Here's what I have now, but I get an error saying The method 'delete' isn't defined for the type 'ChannelState':
var channel = await client.queryChannel('messaging', channelId: widget.channel);
await channel.delete();
Seems pretty simple but I can't get it to work. Any help is appreciated!
client.queryChannels
is used to fetch a list of channels and it returns the channel state data class and not the Channel client.
We suggest querying a single channel using
final channel = client.channel('messaging', id: widget.channel);
await channel.watch(); // if you don't need to watch the channel you can even use channel.query()
Using
channel.delete()
you can delete the channel.