I'm trying to navigate to another screen. However, I'm getting:
Another exception was thrown: Navigator operation requested with a context that does not include a Navigator
I found a solution on GitHub (https://github.com/flutter/flutter/issues/15919) by @burhanrashid52 on how to solve this. But, the example he uses is using a StatelessWidget. Can somebody give me an example on how to solve this with a StatefulWidget? Thanks.
class ToDoState extends State<ToDo> {
@override
Widget build (BuildContext context) {
return MaterialApp(
home: Scaffold(
floatingActionButton: FloatingActionButton(
backgroundColor: Color(0xff00bbff),
child: Icon(
Icons.chat_bubble
),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => NewTask()));
print("test");
}
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SafeArea(
child: Container(
child: Padding(
padding: EdgeInsets.fromLTRB(20, 40, 20, 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Task List",
style: TextStyle(
fontWeight: FontWeight.w800,
fontSize: 22,
color: Color(0xff242424)
),
),
Text(
"1 incomplete",
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
color: Color(0xffb3b3b3)
),
),
],
)
),
),
),
Expanded(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Item("Get shampoo from the store", "Today at 3:49pm", true),
Item("Go to college class", "Today at 3:49pm", true),
Item("Work on the ToDo app", "Today at 5:27pm", false),
Item("Test this app", "Today at 3:49pm", true),
],
)
)
],
),
),
);
}
[1]: https://github.com/flutter/flutter/issues/15919