0

Quiero ver si existe la posibilidad de cambiar de pantalla utilizando la acción de un boton del AlertDialog.

código de introducir el código aquí

AlertDialog(
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(50.0)),
    title: Text(title),
    content: Column(
    //por default esta abarcando el maximo, para evitar eso se cambia para
    // que solo tome el minimo
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
        Text(contenido),
        FlutterLogo(
        size: 100.0,
        )
    ],
    ),
    actions: <Widget>[
    FlatButton(
        child: Text('Cancelar'),
        //permite salir del Alert
        onPressed: () {
            Navigator.of(context).pop();
            // Navigator.pushReplacementNamed(context, '/Inicio');
        }),
    FlatButton(
        child: Text('Reintentar'),
        //permite salir del Alert
        onPressed: () async {
            if (await _validaInternet()) {
                Navigator.of(context).pop();
            }
        }),
    ],
);

Intente colocando las siguiente lineas

Navigator.of(context).pop();
Navigator.pushReplacementNamed(context, '/Inicio');

pero con el

Navigator.pushReplacementNamed(context, '/Inicio');

me da el siguiente error

I/flutter (15930): The following assertion was thrown while handling a gesture:
I/flutter (15930): Could not find a generator for route RouteSettings("/Inicio", null) in the _WidgetsAppState.
I/flutter (15930): Generators for routes are searched for in the following order:
I/flutter (15930):  1. For the "/" route, the "home" property, if non-null, is used.
I/flutter (15930):  2. Otherwise, the "routes" table is used, if it has an entry for the route.
I/flutter (15930):  3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not
I/flutter (15930): handled by "home" and "routes".
I/flutter (15930):  4. Finally if all else fails onUnknownRoute is called.
I/flutter (15930): Unfortunately, onUnknownRoute was not set.

el build del main donde se asignan las rutas

Widget build(BuildContext context) {
    return Provider(
      auth: auth,
      child: MaterialApp(
        routes: getApplicationRoutes(),
        home: result,
        theme: ThemeData(
            primaryColor: Colors.blue,
            // accentColor: Colors.purple,
            fontFamily: 'Lato'),
      ),
    );
  }


Map<String, WidgetBuilder> getApplicationRoutes() {
  final inicio = Inicio();

  return <String, WidgetBuilder>{
    "/Inicio"           : (BuildContext context) => inicio,
  };
}
9
  • puedes intentar lo que hicieron en SO en ingles enlace
    – Artudoxo
    el 8 ago. 2019 a las 17:15
  • @Artudoxo La respuesta que le dan es use algo similar a lo que ya hice Navigator.pushReplacementNamed(context, '/Inicio'); y que me regresa el error que muestro.
    – Richard
    el 8 ago. 2019 a las 17:36
  • Tienes las rutas bien definidas? puedes agregar el codigo de main.dart? el 8 ago. 2019 a las 20:10
  • @diegoveloper ya agrege donde están las rutas quite las demás para evitar colocar mucho código
    – Richard
    el 8 ago. 2019 a las 22:09
  • si le quitas esto : Navigator.of(context).pop(); , y solo dejas el Navigator.pushReplacementNamed(context, '/Inicio'); , que sucede? el 8 ago. 2019 a las 22:12

1 respuesta 1

0

Revisando tu código vi que el problema viene debido a que estás creando 2 widgets de MaterialApp y además estás generando las rutas en el segundo widget.

Elimina el segundo widget de material app, por lo que tu método main quedaría así :

void main() {
  final auth = Auth();
  runApp(Provider(
      auth: auth,
      child: MaterialApp(
        home: MyApp(),
        routes: getApplicationRoutes(),
        theme: ThemeData(
            primaryColor: Colors.blue,
            fontFamily: 'Lato'),
      )));
}

Y el widget aplicacion solo con esto :

  Widget build(BuildContext context) {
    prueba();
    print("APLICACION...");
    return result;
  }

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.