What does the dispose() function actually do under the hood in flutter

Advertisements When we use some controllers in our widgets, I see it that we just make instances, fine But when we call as an example: controller.dispose() what actually the flutter engine exactly do for that constructor >Solution : According to the official source here, the dispose method is a general API that is used commonly… Read More What does the dispose() function actually do under the hood in flutter

How to dispose subscription?

Advertisements How can I dispose subscription if my class is not in StatefulWidge? Is there any method? class EventNotifier extends ValueNotifier<List<String>> { EventNotifier(List<String> value) : super(value); final List<String> events = [‘add’, ‘delete’, ‘edit’]; final stream = Stream.periodic(const Duration(seconds: 5)); late final streamSub = stream.listen( (event) { value.add( events[Random().nextInt(3)], ); notifyListeners(); }, ); } >Solution :… Read More How to dispose subscription?

Is 'using' disposing the instance in this case

Advertisements I’m calling the following method in a loop while it is true, which leads to automatic reconnection. Since I’m using the using keyword, does it dispose the ClientWebSocket on each try/catch return false or it only disposes it if it reaches the end of ConnectAsync? private async Task<bool> ConnectAsync(CancellationToken cancellationToken) { using var clientWebSocket… Read More Is 'using' disposing the instance in this case