Created
August 15, 2021 10:45
-
-
Save nilsreichardt/e0d3b247da70f6080ea5917ce346c5a4 to your computer and use it in GitHub Desktop.
Passing data via Flutter Navigator
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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
home: HomePage(), | |
); | |
} | |
} | |
class HomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Home")), | |
body: Center( | |
child: ElevatedButton( | |
child: const Text("Button"), | |
onPressed: () { | |
Navigator.of(context).push( | |
MaterialPageRoute( | |
builder: (context) => const NextPage("Passed data"), | |
), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class NextPage extends StatelessWidget { | |
final String data; | |
const NextPage(this.data); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Home")), | |
body: Center( | |
child: Text(data) | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment