I am getting this exception while trying to navigate to another page using Navigator.of(context).push() :
lib/main.dart:20:41: Error: A function expression can't have a name. Navigator.push(context, MaterialPageRoute(builder: context){ ^^^^^^^^^^^^^^^^^ lib/main.dart:20:68: Error: Not a constant expression. Navigator.push(context, MaterialPageRoute(builder: context){ ^^^^^^^ lib/main.dart:20:66: Error: Non-optional parameters can't have a default value. Try removing the default value or making the parameter optional. Navigator.push(context, MaterialPageRoute(builder: context){ ^ lib/main.dart: Error: The argument type 'HomePage Function(dynamic)' can't be assigned to the parameter type 'Route'.
Code :
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Are You Present?',
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child:
FlatButton(onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: context){
return HomePage();
}
);
}, child: Text("Press to Continue")),
),
));
}
}