Navegar entre dos pantallas
Con Navigator podemos trasladarnos a otra pantalla (Navigator.push) y después regresar a la pantalla inicial (Navigator.pop).
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: Home(),
));
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Primera Pantalla'),
),
body: Center(
child: RaisedButton(
child: Text('Ir a Pantalla 2'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PantallaDos()),
);
},
),
),
);
}
}
class PantallaDos extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Pantalla 2"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Volver!'),
),
),
);
}
}
Fuente: Navigate to a new screen and back.