Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter – Getting data from an other view – when print getting Instance of 'Future<List<String>?>' instead of the data

I have two views interacting together. On the first view, the user can do a tap on a button, this will display the second view where he can complete a form. When done, I want to transfert the data of the form into an array. This is working.
But, I want to send the array data to the first screen, and use the data of the array in my first view.

Here is how I do that. When I print the variable dataFromFirstAction, I am getting Instance of ‘Future<List?>. What I want is to get the array so I can get access to each fields and use them into my first view. Many thanks.

First view

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

void _openAddEntryDialog(String futureProjectName) async {

    final firstActionData = Navigator.of(context).push(MaterialPageRoute<List<String>>(
        builder: (BuildContext context) {
          return  AddingFirstActionToProjectV2(getprojectName:futureProjectName );
        },
        fullscreenDialog: true
    ),
    );

     setState(() {
       dataFromFirstAction = firstActionData;
       print('firstActionData');
       print (firstActionData.);
     });
  }

Second view

 ElevatedButton(
                onPressed: (){

                  print('PRG:$getprojectName');

                  if(_addFirstTaskFormKey.currentState!.validate()){
                    
                    firstActionToRecord.insert(0,selectedFocusCapture!);
                    
                    Navigator.pop(context, firstActionToRecord);

                  } else{
                    _showSnackBarErrorMessage();
                    print("not validated");
                  }
                }, child: const Text('Press'),
              ),

>Solution :

You need to await the result, like

final firstActionData = await Navigator.of(context).push(MaterialPageRoute<List<String>>(
    builder: (BuildContext context) {
      return  AddingFirstActionToProjectV2(getprojectName:futureProjectName );
    },
    fullscreenDialog: true
),
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading