• Courses
  • YouTube
  • Dev News
  • Technology
  • Blogs
  • Flutter Jobs
  • Contact
    • About Us
    • RegisterLogin
    Navoki
    • Courses
    • YouTube
    • Dev News
    • Technology
    • Blogs
    • Flutter Jobs
    • Contact
      • About Us
    • RegisterLogin

      Developers

      • Home
      • Blog
      • Developers
      • Future class in flutter
      Flutter Future Class

      Future class in flutter

      • Posted by Shivam Srivastava
      • Categories Developers, Android
      • Date October 1, 2019
      • Comments 0 comment
      Spread the love

       

      Introduction

      Hello friends.
      In this blog, I explain about Future class and it’s feature or functionality with code example.
      Generally, beginners confused, what is Future, class how to use it, where we can use it, etc. So don’t skip any single line in this blog for a better understanding of the topic.

      Before starting the code first learn what is Future class

      Future

      A future is used to perform asynchronous tasks in flutter it is defined exactly like a function in the dart, but instead of the void, you use Future. If you want to return a calculated value from the Future then you pass a <data-type>. The future can have a return type as a function return type as you need.

      Future<String>

      Future performs an asynchronous task using Future, Async, Await and Then keyword.

      If you used asynchronous tasks before so maybe you have remembered that we have to use asynchronous tasks only that condition when we have need to perform a long task. For example:-

      Output

      Here first Start printed the getState() is called. Since getState() is Future type and a then() is attached to it. The program does not wait for getState() data and proceed further prints END.

      then

      As we can see that the return value of the getState() has then()which execute when Future function receives a data returned i.e data value is You are learning Future.

      async

      The keyword async makes it execute parallel and occurs after 2 secs delay as await wait for data to return and then proceed further. That’s why program didn’t wait for 5 secs delay code and printed A 5 sec Delay later and in parallel.

      await

      wait for a Future function to return data and then proceeds to next line, mostly you will use then()when you don’t have to wait for data, the logic for that data is in then() , while, in await programs wait for data to returnand assign the value to variable that will be on left of =

      In some exception you might use awaitand thentogether, that depends on your logic.

      Future and sync are used for background processing i.e non-ui thread , for let’s say using REST API, decoding-encoding, Android and iOS Native calls, SQLite storage etc.

      If you have some doubt you can ask and comment below.

      Bookmark(4)

      Please login to bookmark

      Continue with Google
      +1

      Tag:dart future class, flutter future, flutter future class, flutter future example, flutter future then example, flutter wait for future, get value from future flutter

      • Share:
      author avatar
      Shivam Srivastava

      Mobile Solution [email protected], Android and Flutter Dev, Dart ,Founder of @Navoki, Instructor

      Previous post

      Windows 10 in 1 Billion devices
      October 1, 2019

      Next post

      Pixel buds 2
      October 22, 2019

      You may also like

      everything-about-flutter-3-in-google-i-o-2022 navoki.com
      Everything about Flutter 3 in Google I/O 2022
      12 May, 2022
      How Video Call works in Flutter
      How Incoming Video Call Notification works in Flutter
      15 April, 2022
      How-to-Create-Flutter-Desktop-Navoki-Blog
      How to Install Flutter on Windows, macOS and Ubuntu
      11 April, 2022

      Leave A Reply Cancel reply

      You must be logged in to post a comment.


      Categories

      • Android
      • Dart
      • Dart Server
      • Dart Web
      • Developers
      • Flutter
      • Flutter Desktop
      • Flutter Mobile
      • Flutter Web
      • Fuchsia
      • Go Lang
      • Technology
      • Uncategorized

      Recent Post

      • Everything-About-Flutter-3-In-Google-I-O-2022 Navoki.comEverything about Flutter 3 in Google I/O 2022
      • Flutter-Web-Cors-Error-Solved-Navoki.com[SOLVED] Flutter Web CORS Error
      • How Video Call Works In FlutterHow Incoming Video Call Notification works in Flutter

      Subscribe Now

       

      Recent Courses

      Single And Multi Selection Listview In Flutter

      Single and Multi Selection ListView in Flutter

      Go Installation And Variables

      Go Installation and Variables

      List In Dart Programming Language

      List in Dart Programming language

      Variables In Dart Programming Language

      Variables in Dart Programming language

      View All

      DON’T MISS
      FLUTTER UPDATES

      Be the first to know when our blog is published.

      flutter-mobile-mockup

      Check your inbox or spam folder to confirm your subscription.

      Contact

      •   Navoki Technologies Pvt. Ltd.
        JMD Megapolis , Sector 48, Gurugram, Haryana 122018

      Company

      • About Us
      • Blogs
      • Contact
      • Privacy policy
      • Terms & Condition

      Useful Links

      • Courses
      • Youtube
      • Dev News

      Mobile

      Click and Get started in seconds

      "Navoki" is a registered trademark of Navoki.com ® 2020–2030 Navoki Technologies Pvt Ltd.

      • Terms & Condition

      Login with your site account

      Continue with Google

      By "Sign in” above to accept Navoki’s Terms of Service & Privacy Policy.

      Not a member yet? Register now

      Register a new account

      Continue with Google

      By "Sign Up” above to accept Navoki’s Terms of Service & Privacy Policy.

      Are you a member? Login now