Async/Await - Flutter in Focus

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • This is the fourth video in the Flutter in Focus series on asynchronous coding in Dart. In this episode, learn how to use the async and await keywords with Dart's Futures. They can help you avoid nested callbacks and keep your asynchronous code tight and easy to read.
    For more deep dives on things like Stateless and Stateful widgets, Flutter on iOS, and other advanced topics, check out the other episodes of Flutter in Focus.
    Asynchronous programming: futures & async-await → goo.gle/2XJLPSd
    Flutter in Focus Playlist → goo.gle/FlutterInFocus
    Get started with Flutter → flutter.dev
    Try a Flutter codelab → goo.gl/d3fHPo
    Join the conversation → goo.gl/68oUnb
    This video is also subtitled in Chinese, Indonesian, Italian, Japanese, Korean, Portuguese, and Spanish.
    Subscribe to the Flutter channel → goo.gle/FlutterYT
    #dart #darttopic

Komentáře • 132

  • @tonywright3777
    @tonywright3777 Před 4 lety +142

    I wish this guy would teach me everything I ever need to know. So clear and clean. Thanks heaps.

    • @agentstona
      @agentstona Před 4 lety +1

      i assume you are being sarcastic here......... dude he just over complicated the most simplest of explanations ........ he took 9 minutes to explain something that could be done simply in 5 minutes ........ although 9 minutes is not that bad compared to the 20 minute 1 hour junk now days .......

    • @xynyde0
      @xynyde0 Před 3 lety +17

      @@agentstona id like to see you try and do a better job then lol

    • @MadeInPython
      @MadeInPython Před 6 měsíci

      No he is right. The authors of this channel could benefit by learning "Show and don't tell" which was taught way back in high school. I don't care to be lectured on what it can do. SHOW me what it does in Flutter. Also the docs are quite poor in relation to other languages I've learned. It's scattered across different websites and is not comprehensive with a lot of lessons saying "copy + paste this code here". Many people could do a better job. Just My two cents.@@xynyde0

  • @joannabusoba
    @joannabusoba Před 5 lety +2

    Thank you for the series! I hadn't seen this before, glad you have arranged your videos well into a playlist. I'll definitely check it out

  • @codingwithmassodpersiancha2100

    thanks for your efforts , all of you in the flutter team.
    i wish i could use flutter with koltin from day one and still do , but i am beginning to make connections to dart thanks to these series of videos.
    i was wandering the other day in the internals of the flutter api , and was curious how exactly is Row implemented for example and i started to write Row myself . and that helped me to get to know every corner of Row widget. i suggest you shooting videos that talk more about internals. unfortunately being new to Dart , has slowed me digging more inside.
    thanks again and really apperciate what you guys do

  • @Dhruvam
    @Dhruvam Před 5 lety +127

    I am a simple man, I see flutter and I watch the video.

    • @rbp365
      @rbp365 Před 5 lety +10

      Me too. This is just a Dart video essentially though. Dart is the most awesome language I've ever come across, I've read all the official docs I could get on dart.dev. Actually I've never did this to any language

  • @jaayaustin336
    @jaayaustin336 Před 3 lety +4

    This channel is teaching me FLutter while helping me understand Javascript better, thanks!

  • @i_mwanagenzi
    @i_mwanagenzi Před 2 lety +1

    So far, I'm demystifying the entire cloud on asynchronous programming in Flutter. Thanks Flutter team

  • @kpandian1551
    @kpandian1551 Před 4 lety +8

    Amazing explanation. Can’t be more simple. You guys rock it. Love your team’s way of teaching in the Simplest language and that’s another reason why like Flutter so much.
    Many many Thanks to you all !

  • @diegoveloper
    @diegoveloper Před 5 lety +1

    Excellent explanation, very useful! Would be great to watch some videos about RenderObjects in another serie !

  • @aaBeben
    @aaBeben Před 3 lety +11

    This man is a good teacher.

  • @martinseal1987
    @martinseal1987 Před 5 lety

    Loved the video, love your explanations can't wait for the next one

  • @alexblackcat2436
    @alexblackcat2436 Před 2 lety

    very clear and understadable presentation, thanks!

  • @souley-mohamedrochsome9678

    Thank you sir, I am struggling to understand this concept and your explanations are very clear 🙏

  • @hanielbaez5723
    @hanielbaez5723 Před 5 lety

    Nice video, and amazing easy explanation.

  • @d-apps2699
    @d-apps2699 Před 5 lety

    You are amazing! thank you for this video.

  • @MunirHoque
    @MunirHoque Před 4 lety

    I used a lot of Async Await pattern of corutines in Kotlin earlier. While watching this video it seems almost similar, it is very easy to understand.

  • @GamerBizzare
    @GamerBizzare Před 3 lety

    I love u man, You saved my life. Thanks Flutter!

  • @shunjidrahman6860
    @shunjidrahman6860 Před 5 lety +7

    What I have seen on earth ! 😍
    Dart seems so cool 😮

  • @orewaayakashikitsune4537

    Im still new to flutter and new to this async topic cuz i haven't started learning javascript, but this representative explains sooooooo very clear 🤯.

  • @PetrosPollakis
    @PetrosPollakis Před 5 lety

    This video was very helpful! Thanks Google

  • @colectorcell1871
    @colectorcell1871 Před 5 lety

    Always waiting for next video

  • @ryujiganaha9645
    @ryujiganaha9645 Před 3 lety

    Great video. Thank you so much!

  • @longtimedeveloper6498
    @longtimedeveloper6498 Před 3 lety

    Outstanding presentation!

  • @iwandepee
    @iwandepee Před 3 lety

    this man really helps me out (:

  • @crgmonroe
    @crgmonroe Před 4 lety

    Great explanation!

  • @TheBlackManMythLegend
    @TheBlackManMythLegend Před 5 lety

    Great Teacher Onizuka!

  • @Raimkhodzhanov
    @Raimkhodzhanov Před 2 lety +1

    Thank You! Very interesting!

  • @kleytonstn
    @kleytonstn Před 5 lety

    The video is great, flutter is awesome!

  • @garethbeall3674
    @garethbeall3674 Před 4 lety +1

    Such a clear and well thought out explanation - thank you!

  • @PabloMorlock
    @PabloMorlock Před 4 lety

    For what I saw, I concluded that once I used a Future, thereafter I should return a value of some kind of Future. Is it possible to break that depedency, for instance, read an json, an return an map after decode, instead of Future?

  • @mbleftley
    @mbleftley Před 5 lety

    Async/Await is awesome! Flutter is awesome!

  • @imbayi
    @imbayi Před 5 lety +1

    Broken down so well!

  • @gabrielgibeausanchez7

    Is it just me or this guy's charisma is through the roof?

  • @JAICHANGPARK
    @JAICHANGPARK Před 5 lety

    awesome flutter with Async Await Future Stream

  • @Shakl-e
    @Shakl-e Před 5 lety

    You are great, thanks!

  • @remoteportal
    @remoteportal Před 4 lety +4

    Okay, you guys win... I'm wholeheartedly giving up JavaScript; I'm a Dart/Flutter guy now--I'm "all in."

  • @MasterGKH
    @MasterGKH Před 4 lety

    The stream has a mechanism to tell to the "listner" that the stream is end?
    I mean, for example in the code at ~08:00, in the video, when the loop "for" is ended?
    I hope its is clear my question.

  • @frankemeli5918
    @frankemeli5918 Před 5 lety

    Nice one, would like to see a video on state management with providers.
    I love your videos so much that even when I get notified about a new one on the road, I usually don't have the patience to get home before watching.

  • @PelpsRoxXx
    @PelpsRoxXx Před 5 lety +7

    Holy shit!! So async and await are just Future's and then's masked! That's awesome, thanks for the enlightening, keep it up, nice videos!

    • @andrewbrogdon558
      @andrewbrogdon558 Před 5 lety +5

      I know, right? Once you realize that they're just syntax for futures, suddenly async and await are no big deal.

    • @abdallahsani5843
      @abdallahsani5843 Před 4 lety +1

      @@andrewbrogdon558Hi Andrew, I'm new to async I find it interesting though. My question is, Does the for loop wait for the entire stream to finish before it executes?

  • @hdkloh6857
    @hdkloh6857 Před 5 lety +93

    No activity, no fragments, no XML Layout... Only game of widgets.... I like Flutter.

    • @BugGenerat0r
      @BugGenerat0r Před 4 lety +8

      When you play the Game of Widgets, you win, or you go back to Xamarin.

    • @okie9025
      @okie9025 Před 4 lety +4

      If only there was a markup language, preferably HTML, used to create layouts... Well, one can dream

    • @AnonymousAnonymous-nr8su
      @AnonymousAnonymous-nr8su Před 4 lety

      @@okie9025 but html is not markaup language, but some old version of XML DTD.

    • @okie9025
      @okie9025 Před 4 lety +8

      @@AnonymousAnonymous-nr8su remind me what HTML stands for again?

    • @JoyEnergiser
      @JoyEnergiser Před 3 lety +1

      @@okie9025 Ugh html . that's how you will feel about Html once you experience how flutters UI layout works.I felt disgusted that I struggled with it for so long

  • @medamine194
    @medamine194 Před 3 lety

    andrew is the best teacher ever Periodt.

  • @serzen
    @serzen Před 3 lety

    I've watched this video n-times and I still getting stuff from it

  • @nidafatima5000
    @nidafatima5000 Před 5 lety

    hi , I need to know exact build apk process for all platform we tried and get success in android -arm64bit only but we need to test all other platforms pls help me.

  • @KenrickBeckett
    @KenrickBeckett Před 5 lety +1

    "cue word" :) @6:49 Keep up the good work guys!

    • @andrewbrogdon558
      @andrewbrogdon558 Před 5 lety +3

      On the one hand, I'm sad someone noticed, but on the other hand it means someone made it nearly seven minutes into the video before getting bored and loading a different one. :)

    • @pida9669
      @pida9669 Před 4 lety

      @@andrewbrogdon558 You are an excellent presenter. Complaining about the slight mispronunciation of a syllable in your presentation is like complaining about a microscopic inclusion (flaw) in a VVS diamond. :-)

  • @deliriouslee2079
    @deliriouslee2079 Před 3 lety

    wow,this man looks really kind.

  • @Algardraug
    @Algardraug Před 3 lety

    Okay, so I'm still a bit confused as to in what thread async functions/tasks execute? If I wait await for some resource intensive task, will my app stutter?

  • @DiazGunturFebrian
    @DiazGunturFebrian Před 5 lety

    At 7:59 the parameter should be Stream numbers so that we can for loop? CMIIW

    • @chewie7235
      @chewie7235 Před 5 lety

      You're wrong.

    • @andrewbrogdon558
      @andrewbrogdon558 Před 5 lety

      @@basselcheaib Exactly! With await-for, the loop iterates over the values produced by the stream, so there's no need for a list.

  • @karansoni3543
    @karansoni3543 Před 5 lety

    anyone suggest me how to take a printout of a widget(ID Card Generated by flutter app ) in flutter

  • @_Amilio_
    @_Amilio_ Před 3 lety

    How does the await for know that the stream is complete?

  • @dasdunetechnologies1695

    reverse video 2 and 3 in the list. Future event

  • @aakashjana6225
    @aakashjana6225 Před 4 lety

    This concept originates from Python which is also a language that executes on a single core of the cpu unlike compiled languages like Java. (Although dart is also compiled)

  • @Parul_Nandwani
    @Parul_Nandwani Před 4 lety

    hey team, help me out..I am getting this error when trying to insert data into my SQL database. the error is --- socketException: connection timed out, errno = 110, address = 120.00.0.000, port = 44103. I have added "access control allow origin" in my PHP but still getting this.

  • @codewa7605
    @codewa7605 Před 3 lety

    is there a way to cancel the callout?

  • @meowmeowmeow5332
    @meowmeowmeow5332 Před 5 lety

    Very nice

  • @pspdito
    @pspdito Před 4 lety

    learned a lot of clean code and data structures oh yeaa

  • @bsizeindian3966
    @bsizeindian3966 Před 4 lety +2

    Where is your button?

  • @aminebenichou4818
    @aminebenichou4818 Před 3 lety

    I am getting when calling a function

  • @hurbangash1302
    @hurbangash1302 Před 2 lety

    thanks

  • @soroush51
    @soroush51 Před 4 lety

    if there could be 'else' keyword to execute when try section ran without any errors and successfully(like python) it would be great

    • @marflage
      @marflage Před rokem

      Is not the code right after the try-catch block a kind of else for the execution of the program?

  • @Gamex996
    @Gamex996 Před 5 lety

    1:30 lies, will I had a lot of issues with .then because it gives null and goes on

    • @minma02262
      @minma02262 Před 4 lety

      Either you are not returning, or your return is null

  • @refayetshanto
    @refayetshanto Před 2 lety

    Hi, your videos really helped me learn flutter in a very simplistic way. One somewhat related question which will do a big favour to me. Why I can't assign a Future to int. I simply want to assign Future to an int variable. Please help.

    • @marflage
      @marflage Před rokem

      You can not assign a Future to a non-Future. While assigning a Future to a variable of type int, you are essentially only assigning an empty box (from the gift analogy from the video on Futures, also talked about in this video) to the variable. When a Future starts getting executed, it first returns an empty box to the calling statement as an indication that the Future has not completed yet. When a Future has completed executing, it returns the actual data or error to the calling function. When you do int i = Future, you are only getting the first return (the empty box) and the int variable accepts no further values; because non-Future variables need instant access to values and thus cannot wait. Now to make the variable wait for the actual useful data, we can use the await keyword before the Future expression. Like so: int i = await Future

  • @TinBuz
    @TinBuz Před 4 lety

    Flutter/Dart is a dyslexic coder’s dream

  • @felixtopappz7338
    @felixtopappz7338 Před 4 lety

    Can flutter be used on rapidApi.com to make calls

  • @jmarms
    @jmarms Před 5 lety +2

    I really dig that shirt.

    • @JulianoPenna
      @JulianoPenna Před 6 měsíci

      What does that mean? I know it's California, but what about the "blank region"?

  • @nimishkhattar2017
    @nimishkhattar2017 Před 3 lety

    crystal clear

  • @mateusfccp
    @mateusfccp Před 4 lety +6

    I still prefer .then syntax.
    Future createData() =>
    _loadFromDisk()
    .then(_fetchNetworkData)
    .then((data) => ProcessedData(data));
    It's clearer for me.

    • @marflage
      @marflage Před rokem

      It helps in understanding the code but reduces readability. Not to mention, the then syntax really takes a hit on both readability and understandability when the logic becomes convoluted and there are many nested thens in thens.

  • @MdSiam-kw5ox
    @MdSiam-kw5ox Před 2 lety +1

    Future API is awesome 😍

    • @flutterdev
      @flutterdev  Před rokem

      Very awesome, Md! We're excited about the future too 😍
      Have you checked out our Dart codelabs? Catch up here👀: goo.gle/3xjc7Qe

  • @kirill4531
    @kirill4531 Před 5 lety +3

    Yeah, a sequence of multiple "then((){}" looks piled up

  • @junior.santana
    @junior.santana Před 4 lety

    Ok I understood how to use it but the question I'm struggling is why to use it?
    I have to wait for the disk/network response anyway.
    I mean, what kind of problem I would be solving?

    • @jackma1241
      @jackma1241 Před 4 lety

      It will help you handle async job in syny way, especially interact with UI code. For example, if you need to load an image from network after clicking a button, it would be messy to use Future API, or even more messy to use a thread like in Java. But in dart, you can create an async method, write both your UI code and blocking operation in it, like show a loading dialog, await image to be loaded, hide loading, using try catch with exception, all in a sync way without blocking UI. Your code would be much more clear.

  • @notanenglishperson9865

    What async* does?

  •  Před 5 lety

    Hello, do you know how can I list my instagram followers with flutter ? I want to make something on social media with flutter but I dont know how can I use my social media with flutter ?

    • @andrewbrogdon558
      @andrewbrogdon558 Před 5 lety +1

      Instagram has an HTTP API (at least as far as I can tell), and you can certainly make HTTP requests with Flutter and display the results!

  • @roykarseboom9185
    @roykarseboom9185 Před 3 lety

    Why do you need to mark function with async tag? It's just confusing because functions with Futures without async keyword also run asynchronously... anyway, I like the videos :)

  • @hamzacodes2785
    @hamzacodes2785 Před 3 lety

    which country is on his t-shirt?

    • @JulianoPenna
      @JulianoPenna Před 6 měsíci

      That is California, not a country. But I'd like to know what that "blank region" means.

  • @engMark90
    @engMark90 Před 2 lety

    But there is a difference between then & await, await will not execute the lines after it until resolves, on the other hand "then" will execute the following lines and resolve sometime later then execute the callback.

    • @engMark90
      @engMark90 Před 2 lety

      I just want to focus on the point that Yes await is a syntactic sugar for nested then, but the following lines after in the same scope will never be executed when using await, however it does when using "then"

  • @SalemTech
    @SalemTech Před 5 lety

    I think i have a problem relative to this concept i guess!
    I'm trying to push notifications locally in a flutter app
    these notifications are repeated daily at a specific time .. i have four notifications at different four times to be sent but only one is sent !! and the others cancelled i do not know what is the reason but these notifications are sent in an async way
    can you help me ?!
    i'm using the flutter_local_notifications plugin

  • @johnaldrin5924
    @johnaldrin5924 Před 5 lety +1

    Cons to using async/await? I think we are being done a disservice by not mentioning when async/await is not the best choice. If I have long running async function will it impact the UI?

    • @rolfhendriks5362
      @rolfhendriks5362 Před 5 lety

      Async/await does not give you the full power of using futures directly. For example there is no async/await equivalent of Future.wait to spawn several async tasks concurrently and wait for all to finish, optionally failing the entire set of tasks on the first error. Async/await is just a thin layer of syntactic sugar around the normal task of executing one or more asynchronous operations sequentially. Async/await, being syntactic sugar on top of futures, does not actually block execution of a function, so your UI will not be impacted by async/await. So to be clear: an async method actually returns as soon as it encounters an await call, not when the results come in.

  • @StEvUgnIn
    @StEvUgnIn Před 5 lety +3

    Watch out, Xamarin

  • @dxvfdfx
    @dxvfdfx Před rokem

    as Android developer we need this kind of video explanation of how Kotlin flow works, if anyone has the video link, please share thanks

  • @claudiubele4892
    @claudiubele4892 Před 3 lety

    "... and the first time I saw them I remember being weirded out"

  • @harry356
    @harry356 Před 2 lety

    I miss the advantage if you use await on each method call. I don't see an improvement from sychronous coding? Why not old fashioned let the programmer decide if an IO intensive thread should be spawned?

  • @davidagyakwa288
    @davidagyakwa288 Před 2 lety

    this has to be updated for the new isolate update 🤷🏾‍♂️

  • @dannykay4919
    @dannykay4919 Před rokem

    Nice explanation w/ trivial examples. How about calling async methods from a build context, this is flutter after-all not just dart.. I see odd behavior frequently that doesn't seem in line w/ this explanation..

  • @vballaddict75252
    @vballaddict75252 Před 3 lety

    "Finally" block executes AFTER the return statement!!! Ouch. I think my old C-oriented mind may need to be reset... :-)

  • @peruviancode1360
    @peruviancode1360 Před 5 lety +1

    Using await is most simple 😂😂

  •  Před 3 lety

    Forgot to explain how to handle the returned Future. That's the painful bit, IMHO

    • @michaelrogers6935
      @michaelrogers6935 Před 3 lety

      That was covered in a previous video - the easiest way is to pass it to a FutureBuilder.

  • @sasat0ru
    @sasat0ru Před 3 lety

    i thing u can say 'just like javascript' and end the video ;P

  • @keepdream
    @keepdream Před 5 lety +1

    please google make a framework that can use html&css&js to produce android and ios application

  • @reapergrim5324
    @reapergrim5324 Před 2 lety +1

    Please use black background in future videos , watching this at night hurts .

    • @flutterdev
      @flutterdev  Před 2 lety +1

      Hi! Thank you very much for the feedback. We have shared your suggestion to our production team 😀

  • @TheCodeWhisperer0o0
    @TheCodeWhisperer0o0 Před 10 měsíci

    does anyone gets benefit from these videos?! I mean practicaly and using inside the code, I know that you would get an idea basically.

  • @yangyun6221
    @yangyun6221 Před rokem

    Flutter guides make Android courses like amateurs

  • @marduchok
    @marduchok Před 5 lety

    Ohio is a state

  • @hackaholic01
    @hackaholic01 Před rokem

    Looks so dump, if you wating then there is no asyn here, all are waiting on other, what uses it have,One can load data from disk and do network call, Why to make things complected, Achieving sync call using async, what a noob development here.

  • @heshansandeepa9471
    @heshansandeepa9471 Před 2 lety +1

    Very nice