Home > database >  Flutter - Getting data from an other view - when print getting Instance of 'Future<List<S
Flutter - Getting data from an other view - when print getting Instance of 'Future<List<S

Time:09-29

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

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'),
              ),

CodePudding user response:

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
),
);
  • Related