- The cause of
- Error reason
- The solution
The cause of
Error when Navigator jumps:
Navigator.push(context, MaterialPageRoute(
builder: (context) => MainPage()
) );
Copy the code
Error reason
To use a Navigator, the root control cannot be directly MaterialApp.
The solution
Jump to the StatefulWidget at runtime using the StatelessWidget;
void main(a) {
runApp(FlareDemo());
}
class FlareDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
returnMaterialApp( home: FlareSignInDemo() , ); }}class FlareSignInDemo extends StatefulWidget {
@override
_FlareSignInDemoState createState(a) => _FlareSignInDemoState();
}
class _FlareSignInDemoState extends State<FlareSignInDemo> {
FlareSignInController _signInController;
@override
void initState(a) {
_signInController = FlareSignInController();
super.initState();
}
@override
Widget build(BuildContext context) {
returnMaterialApp( home: Scaffold( body: Theme( data: Theme.of(context).copyWith( primaryColor: Colors.black54, ), child: RaisedButton(onPressed: () { Navigator.push(context, MaterialPageRoute( builder: (context) => MainPage() ) ); },),),),); }}Copy the code