I'm trying to make the other page with the button but after debugging this code, the button called 'Next' appears but when I click the button, nothing happens and this error comes in "Navigator operation requested with a context that does not include a Navigator." Could someone help me out? Thank you a lot:)
import 'package:flutter/material.dart';
void main() {
runApp(MyApp(
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController nameController = TextEditingController();
TextEditingController ageController = TextEditingController();
TextEditingController addressController = TextEditingController();
TextEditingController weightController = TextEditingController();
TextEditingController heightController = TextEditingController();
TextEditingController traitController = TextEditingController();
TextEditingController appearanceController = TextEditingController();
String fullName = '';
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.pink,
),
home: Scaffold(
appBar: AppBar(
title: Text('Input Information'),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.purple,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
body: Center(
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: nameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Full Name',
),
)),
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: ageController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Age',
),
)),
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: addressController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Address',
),
)),
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: weightController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Weight',
),
)),
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: heightController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Height',
),
)),
Container(
margin: EdgeInsets.all(20),
child: TextField(
controller: traitController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Unique Trait',
),
)),
// Container(
// margin: EdgeInsets.all(20),
// child: TextField(
// controller: appearanceController,
// decoration: InputDecoration(
// border: OutlineInputBorder(),
// labelText: 'Apperance',
// ),
// )),
ElevatedButton(
child: Text('Next'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
Container(
margin: EdgeInsets.all(20),
child: Text(fullName),
)
]))),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Camera"),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Back"))));
}
}