Skip to content

Instantly share code, notes, and snippets.

@igabice
Last active January 23, 2020 14:41
Show Gist options
  • Save igabice/2f74ef77b0c7dd97373c534760bfc284 to your computer and use it in GitHub Desktop.
Save igabice/2f74ef77b0c7dd97373c534760bfc284 to your computer and use it in GitHub Desktop.
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