1
Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        body: Container(
          padding: EdgeInsets.fromLTRB(10.0, 50.0, 10.0, 10.0),
          child: Column(
            children: [
              TextField(
                controller: user,
                decoration: InputDecoration(
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(20.0)),
                    hintText: "ENTER USER NAME"),
              ),
              SizedBox(
                height: 10.0,
              ),
              TextField(
                controller: pass,
                decoration: InputDecoration(
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(20.0)),
                    hintText: "ENTER USER NAME"),
              ),
              FlatButton(
                  onPressed: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) => Home()));
                  },
                  child: Text("NAVIGATOR"))
            ],
          ),
        ),
      ),
    );
  }

getting error in navigator.push

"This is the error I am getting while on the press" The following assertion was thrown while handling a gesture:

Navigator operation requested with a context that does not include a Navigator.The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.

Ravi Garg
  • 1,378
  • 12
  • 23

1 Answers1

0
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
  body: Container(
    padding: EdgeInsets.fromLTRB(10.0, 50.0, 10.0, 10.0),
    child: Column(
      children: [
        TextField(
          controller: user,
          decoration: InputDecoration(
              border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(20.0)),
              hintText: "ENTER USER NAME"),
        ),
        SizedBox(
          height: 10.0,
        ),
        TextField(
          controller: pass,
          decoration: InputDecoration(
              border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(20.0)),
              hintText: "ENTER USER NAME"),
        ),
        FlatButton(
            onPressed: () {
              Navigator.push(
                  context, MaterialPageRoute(builder: (context) => Home()));
            },
            child: Text("NAVIGATOR"))
      ],
    ),
  ),
)
);
}

PLease Write code like this , whenever asking doubt on any platfom

also Please provide the code of Home()

here is the changed code for Home()

import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  HomeState createState() => HomeState();
}

class HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
     return Scaffold(
        body: Container(
          child: Column(
            children: [
              Text(
                "WELCOME",
                style: TextStyle(fontSize: 50.0),
              )
            ],
          ),
        ),
      );
  }
}
Aman Verma
  • 818
  • 5
  • 17