skip to Main Content

Hi I’m a beginner on Flutter is there any way to initialize a varirable with another variable that’s declared above it ?

2

Answers


  1. You can do lazy initialization by adding late on second variable declaration like

    Foo foo = Foo();
    late int data= foo.value;
    
    Login or Signup to reply.
  2. Yes you can by initializing the second variable in the initState() Function in statefulWidget class .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search