I am trying to navigate to another screen using the Navigator On Pressed function so that when pressing the MaterialButton, it connects to another screen, the problem is that when entering the code, it marks an error in "Context". Attached code.
Widget _boton1(String texto) {
return MaterialButton(
child: Text(
texto,
style: TextStyle(color: Colors.black),
),
color: Colors.orange[100],
elevation: 1,
padding: EdgeInsets.all(60),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
side: BorderSide(color: Colors.black),
),
onPressed: () {
Navigator.push(context, //Error en Context
MaterialPageRoute(builder: (context) => PaginaPrincipal()),
);
},
);
}
You may be putting the widget
_boton1
outside the class, make sure you put the button inside the class: