Isolates in Flutter with Example | Flutter Concurrency

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we will be talking about isolate in flutter before we start don't forget to hit the Subscribe button in flutter an isolate refers to a separate concurrent execution track allowing you to perform computations in the background without blocking the main UI Trad isolates are a dark language feature and flutter leverage them to handle task concurrently unlike trads isolate don't share memory which helps to avoid common concurrency issues and instead rely on message passing mechanism to talk with each other here is a brief overview on how isolate Works in flutter when you run a flutter app the main function runs in the main isolate this isolate is responsible for handling the UI and user interactions you can then create additional isolates to perform background tasks such as heavy computations Network requests or other operations that might otherwise block the main threat and return the results to the main isolate threats so now let's dive into the code firstly I will create an isolate function this function will perform heavy computations for example in this tutorial I will create a for Loop that adds up an integer from one to a huge number as I mentioned earlier isolate rely on message passing mechanism so we have to pass in a send Port into this function send Port is responsible to send the results to the received port in a form of message so after the full loop finished we will send the result out using the send Port now coming to the elevated button on press firstly we have to create the receive Port that act as a receiver of the message then we have to create an isolate instance using isolate dos spawn function and inside this function is where we execute the isolate function that we have created above next is where we receive messages from the spawn isolate in the main isolate for tutorial purposes I will just add a print statement to the isolate function result now let's try it out in the simulator so as you can see when I click on the elevated button it printed out the result to the console and the UI did not stutter or Jank so this is how you perform heavy operation without affecting the UI performance using isolate conclusion isolates are a powerful tool however not all task require isolates flutter provides other mechanisms such as future and a syn await for handling a synchronized operation without creating additional isolates and this mechanisms are good enough to handle most of the computation if you have any question feel free to comment below don't forget to like the video and subscribe to our Channel see you in the next video
Info
Channel: AI with Flutter
Views: 1,163
Rating: undefined out of 5
Keywords: isolates in flutter, flutter concurrency, flutter async/await, dart concurrency
Id: NA_CaQtfNOA
Channel Id: undefined
Length: 4min 16sec (256 seconds)
Published: Mon Dec 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.