Skip to content

Instantly share code, notes, and snippets.

@stegrams
Created May 16, 2020 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stegrams/a8812550ee0a2f84dab8f0a2bf1ac14b to your computer and use it in GitHub Desktop.
Save stegrams/a8812550ee0a2f84dab8f0a2bf1ac14b to your computer and use it in GitHub Desktop.
A pushReplacementNamed navigation with arguments.
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => AuthService(),
'/dash': (context) => DashBoardScreen(),
},
),
);
}
class AuthService extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Auth Service Screen')),
body: Center(
child: RaisedButton(
child: Text("Login!", style: TextStyle(fontSize: 20)),
onPressed: () => Navigator.pushReplacementNamed(
context,
'/dash',
arguments: {"name": "Foo Bar", "email": "foobar@baz.com"},
),
),
),
);
}
}
class DashBoardScreen extends StatelessWidget {
Widget build(BuildContext context) {
Map<String, String> args = ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(title: Text('Dash Board Screen')),
body: Center(
child: Text(
"Name: ${args['name']}\nEmail: ${args['email']}",
style: TextStyle(fontSize: 20),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment