Flu_Py Developer
Flu_Py Developer

Reputation: 231

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.

Upvotes: 0

Views: 41

Answers (1)

Mr vd
Mr vd

Reputation: 988

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)
          );
        },
      ),
    );
  }
}

Upvotes: 1

Related Questions