Last active
January 23, 2020 14:41
-
-
Save igabice/2f74ef77b0c7dd97373c534760bfc284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:routing_prep/main.dart'; | |
class RouteGenerator { | |
static Route<dynamic> generateRoute(RouteSettings settings) { | |
//Get arguments passed in Navigator.pushNamed | |
final args = settings.arguments; | |
switch (settings.name) { | |
case '/': | |
return MaterialPageRoute(builder: (_) => FirstPage()); | |
case '/second': | |
return MaterialPageRoute(builder: (_) => SecondPage(data: args,)); | |
default: | |
// If there is no such named route in the switch statement, e.g. /third | |
return MaterialPageRoute( | |
builder: (_) => Scaffold( | |
body: Center( | |
child: Text('No route defined for ${settings.name}')), | |
)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment