Search code examples
androidflutternavigator

How to push values with Navigator and recieve them?


I need know how to push values from a screen to another screen with Navigators, because I searched and and didn't understand how it works to push and recieve data and values, or what is the best way to share values to of a screen to another screen.

UPDATE

Look I want to push the var videoPath value to the previuos screen after finishing the _stopvideoRecording() Future function.


Solution

  • Refer this official doc of Flutter

    Code to send data to new Screen 
    
     Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => DetailScreen(todo: todos[index]),
          ),
        );
    

    Second Page/Receiving page

     class TodosScreen extends StatelessWidget {
      final List<Todo> todos;
    
      //requiring the list of todos
      TodosScreen({Key key, @required this.todos}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Todos'),
          ),
          //passing in the ListView.builder
          body: ListView.builder(
            itemCount: todos.length,
            itemBuilder: (context, index) {
              return ListTile(
                title: Text(todos[index].title)
              );
            },
          ),
        );
      }
    }