Created
May 16, 2020 00:07
-
-
Save stegrams/a8812550ee0a2f84dab8f0a2bf1ac14b to your computer and use it in GitHub Desktop.
A pushReplacementNamed navigation with arguments.
This file contains hidden or 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'; | |
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": "[email protected]"}, | |
), | |
), | |
), | |
); | |
} | |
} | |
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